Page 1 of 1
When to use __LINE__ , __FUNCTION__, and __CLASS__ ??
Posted: Sat Jun 11, 2005 2:26 pm
by mudvein
I've read up on __LINE__, __CLASS__, and __FUNCTION__, but I can't seem to figure out why and where to use them? Could anyone shed some light on this for me? Thanks
Posted: Sat Jun 11, 2005 2:29 pm
by hawleyjr
Those constants vars are typically used with error checking.
Code: Select all
....
if($error){
echo 'Error in '.__FUNCTION__.' Function ';
}
Posted: Sat Jun 11, 2005 2:31 pm
by mudvein
yeah, but i've seen them used for passing data?
Code: Select all
$blah = __CLASS__.'::'.__FUNCTION;
$a->query($string,$blah,__LINE__);
?? so i can't undersstand why __LINE__ would be passed. or either of the other 2 constants?
Posted: Sun Jun 12, 2005 9:27 am
by Skara
you could put them in an error class.
Code: Select all
do_this() or uhoh(__CLASS__,__FUNCTION__,__LINE__);
Posted: Sun Jun 12, 2005 11:24 am
by shiznatix
mudvein wrote:yeah, but i've seen them used for passing data?
Code: Select all
$blah = __CLASS__.'::'.__FUNCTION;
$a->query($string,$blah,__LINE__);
?? so i can't undersstand why __LINE__ would be passed. or either of the other 2 constants?
dunno why they would pass __LINE__ in a query unless you want to do somtin like this
Code: Select all
$do_query = mysql_query($query) or die(mysql_error().__LINE__);
Posted: Sun Jun 12, 2005 11:47 am
by hawleyjr
mudvein wrote:yeah, but i've seen them used for passing data?
Code: Select all
$blah = __CLASS__.'::'.__FUNCTION;
$a->query($string,$blah,__LINE__);
?? so i can't undersstand why __LINE__ would be passed. or either of the other 2 constants?
Can you show an example of where you saw this code? Maybe that will help...?
Posted: Mon Jun 13, 2005 6:48 am
by Syranide
You pass the line in order to see where the query originated from, otherwise not possible without a debug backtrace.
Posted: Mon Jun 13, 2005 10:19 am
by mudvein
well, after looking through this stuff a little closer, you all are right. it's basically being used for error reporting. thanks and sorry

lol
Posted: Mon Jun 13, 2005 10:28 am
by phpScott
don't be sorry, I haven't moved onto the fancy php5 stuff yet, so i find it very informative
