File controller.php looks like:?phpinclude("common.php");include("user.php");$user = new user();?>File user.p" name="description" /> File controller.php looks like:?phpinclude("common.php");include("user.php");$user = new user();?>File user.p" />

“Use of undefined constant” notice, but the constant should be defined


there are three files: common.php, controller.php and user.php.

File common.php looks like:

<?php define("MAXIMUM_NAME_LENGTH", 50); ?>

File controller.php looks like:

<?php include("common.php"); include("user.php"); $user = new user(); ?>

File user.php looks like:

<?php class user{ private $var = MAXIMUM_NAME_LENGTH; } ?>

When executing script there is given notice: Notice: Use of undefined constant MAXIMUM_NAME_LENGTH - assumed 'MAXIMUM_NAME_LENGTH' in /.../controller.php on line xxx. I want to share defined values in common.php between other files. How to do it in a proper way?


Generally you would have all defines included by the file that is going to use them. IE: In your example, make the class file have a $class->setMaxNameLength(); method and pass the name length define in through there, that way it won't throw you an error.


Place error_reporting(E_ALL); the line before include("common.php");.

Most probably you'll see something like:

Warning: include(common.php) [function.include]: failed to open stream: No such file or directory in xxx

indicating that your three files are not in the same folder together, or together in a path that is not in your include_path, or a combination of that.


If you are using <a href="" rel="nofollow">Suhosin</a>, check your suhosin.executor.include.* settings.


  • Override FROM image's ENV in Dockerfile
  • How to choose which JUnit5 Tags to execute with Maven
  • where is chrome CSS Reference
  • How to add multiple entries to a plist dictionary with PlistBuddy
  • Sql indexes vs full table scan
  • drop duplicates pandas dataframe
  • Does sql server minds the way records where inserted?
  • Call task's updateProgress
  • Class implementation in a header file == bad style? [duplicate]
  • Find unique tuples in a relation represented by a BDD
  • Base Internationalization and “Could not find a storyboard named […]”
  • UITableView takes much longer to load when numberOfRows returns a large number
  • How to write string.Contains(someText) in expression Tree
  • What do I do with this error when I run tests in rails?
  • Get all existing pointers to an object
  • In Akka, is ActorContext thread safe?
  • How to use the resource module to measure the running time of a function?
  • Access user's phone number on iOS 7
  • Getting error 'Cannot read property 'document' of undefined' while importing exp
  • NUnit 3.0 TestCase const custom object arguments
  • Code in Job's Script Block after Start-Process Does not Execute
  • Time complexity of a program which involves multiple variables
  • DomPDF {PAGE_NUM} not on first page
  • Using $this when not in object context
  • Javascript simulate pressing enter in input box
  • How do I fake an specific browser client when using Java's Net library?
  • How reduce the height of an mschart by breaking up the y-axis
  • Accessing IRQ description array within a module and displaying action names
  • Finding past revisions of files in StarTeam w/ .NET SDK / C#
  • javascript inside java/jsp code
  • Javascript Callbacks with Object constructor
  • Perl system calls when running as another user using sudo
  • Where to put my custom functions in Wordpress?
  • Javascript + PHP Encryption with pidCrypt
  • Importing jscolor library in angular 2
  • Apache 2.4 - remove | delete | uninstall
  • A cron job substitute?
  • Proper folder structure for lots of source files
  • Is there any way to bind data to data.frame by some index?
  • How can I use `wmic` in a Windows PE script?