Re: Trying to use __FILE__ & __LINE__ in generic debugging routine.

From: Date: Sun, 05 Nov 2000 19:06:34 +0000
Subject: Re: Trying to use __FILE__ & __LINE__ in generic debugging routine.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-23799@lists.php.net to get a copy of this message
The reason why what you want to do doesn't work in PHP is that __FILE__ and __LINE__ are special constants. So if you define FOO to be __FILE__ . __LINE__ then FOO is going to contain the FILE and LINE number from where you defined FOO. Every reference now to FOO is defined and static, where as __FILE__ and __LINE__ are special and change as the file/line numbers change. Keep in mind that this is not a bug. PHP is doing exactly what you told it to do, only the behavior is not what you expected. -jeremy brand _______________________________________________________________________ GnuPG Fingerprint: 9F5E 95E0 1CC2 E054 84EA 6099 8ACD 9DBA D2C0 5EA9 _ http://www.JeremyBrand.com/Jeremy/Brand/Jeremy_Brand.html for more __ On Sun, 5 Nov 2000, Neil Kimber wrote: > Date: Sun, 5 Nov 2000 16:01:56 -0000 > From: Neil Kimber <neil.kimber@flytxt.com> > To: php-general@lists.php.net > Subject: [PHP] Trying to use __FILE__ & __LINE__ in generic debugging routine. > > I want to write a debug routine that outputs my debug comments wherever I > want. So, for example I may want to write: > > myDebug("Adding customer to database."); > > What would be most useful is if I could also output the file and line number > that generated the comment. I can do this with: > > myDebug(__FILE__ . __LINE__ . ": Adding customer to database."); > > But, I don't want to have to keep on typing '__FILE__ . __LINE__'. If this > were C I could define a value for the preprocessor to resolve (i.e. #DEFINE > DBOPTIONS __FILE__ . __LINE__ .) But I can't do this in PHP. Is there any > other way that I can define my debug routine so that I can output the File > and Line number without having to keep specifying them directly? > > The perfect solution would enable me to write simply: > > myDebug("Adding customer to database."); > > > Thanks, > Neil > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#23799) next »