How to access a constant from within a class method
I'm migrating a php application from procedural to oop.
I use a DEBUG constant to activate errors and warnings output (in fact, I have thee, every one makes the output more verbose. But I can't find a way to access those constants from within a method. The constants are defined before autoload in a separate file.In the utility file I have
define('DEBUG', TRUE);
And inside a given method I tried to
if(!defined('DEBUG')) define('DEBUG', FALSE);
But I always end up with DEBUG=FALSE.
What am I doing wrong? I'm a total noob to oop, so be gentle please :-)Clarification
Every class has his own file.
In any given script, the first thing I do is to include the utility file. The utility file is the one who defin开发者_开发知识库es DEBUG and has the _autoload function.script_file.php
includes utility_file.php
defines DEBUG
has _autoload function
according to this, you should access DEBUG (no prepending $) in your code directly. are you including or requiring your utility file in the same file that has the function you're talking about? i don't think this is an OOP problem
darkphoenix was right, This wasn't an OOP problem. This was a NetBeans problem.
I'm using NetBeand and uploading the files to a remote server upon save. I've set the DEBUG constant to TRUE in the utility file and hit save on NetBeans, the save process (apparently) went without problems (no warnings or anything).
Big was my surprise when latter I logged in via SSH did a cat on the file. The file was never saved to the server. My local copy has my last edit, but the remote one doesn't...
Moral of the story: I hate you NetBeans
精彩评论