phpmagic-constants

Best practices for usage of PHP’s Magic Constants


What are the best practices for usage of PHP’s Magic Constants, such as __LINE__ , __FILE__, __FUNCTION__, __CLASS__ and __METHOD__?

For example I use __LINE__ and __CLASS__ to locate the SQL Error like this :

$result = mysql_query($query)
or die("Error SQL line ".__LINE__ ." class ".__CLASS__." : ".mysql_error());

Is this an acceptable practice?


Solution

  • The practice you show has two shortcomings:

    Other than that, using these constants is perfectly acceptable. Note that

    docs