note 84353 deleted from language.oop5.constants by danbrown
| From: | danbrown@php.net | Date: | Wed, 03 Aug 2011 13:28:46 +0000 |
| Subject: | note 84353 deleted from language.oop5.constants by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-182175@lists.php.net to get a copy of this message | ||
Note Submitter: anthony dot scaife at firedupgroup dot co dot uk
----
I don't understand the issues you all seem to be having with class constants.
For me they are simply another method of grouping related functions and data together in a logical
package, and keeping things out of global scope.
Class constants were something I felt very much missing from PHP4 (I have a background in C++).
You can use them like this
<?php
class mySql
{
const ERR_CONN = 'Connection attempt failed';
const ERR_SELECT_DB = 'Database selection attempt failed';
const ERR_QUERY = 'Invalid SQL query';
// .... etc
}
?>
Later, you could then use the constants like this
<?php
$err = $db->getErr();
echo "<!-- DB failure : $err -->";
switch($err)
{
case mySql::ERR_CONN: // Do this
case mySql::ERR_SELECT_DB: // Do that
case mySql::ERR_QUERY: // Do something else
}
?>
and if you need to find what other constants the class uses, you just find the class !