When to use __LINE__ , __FUNCTION__, and __CLASS__ ??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mudvein
Forum Commoner
Posts: 45
Joined: Wed Mar 16, 2005 4:39 pm

When to use __LINE__ , __FUNCTION__, and __CLASS__ ??

Post 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
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Those constants vars are typically used with error checking.

Code: Select all

....

if($error){

echo 'Error in '.__FUNCTION__.' Function ';

}
mudvein
Forum Commoner
Posts: 45
Joined: Wed Mar 16, 2005 4:39 pm

Post 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?
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

you could put them in an error class.

Code: Select all

do_this() or uhoh(__CLASS__,__FUNCTION__,__LINE__);
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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__);
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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...?
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post by Syranide »

You pass the line in order to see where the query originated from, otherwise not possible without a debug backtrace.
mudvein
Forum Commoner
Posts: 45
Joined: Wed Mar 16, 2005 4:39 pm

Post 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
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

don't be sorry, I haven't moved onto the fancy php5 stuff yet, so i find it very informative :D
Post Reply