note 84353 added to language.oop5.constants

From: Date: Thu, 10 Jul 2008 09:42:28 +0000
Subject: note 84353 added to language.oop5.constants
Groups: php.notes 
Request: Send a blank email to php-notes+get-141350@lists.php.net to get a copy of this message
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 ! ---- Server IP: 87.124.64.96 Probable Submitter: 83.67.6.200 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.constants.php Edit -- https://master.php.net/note/edit/84353 Del: integrated -- https://master.php.net/note/delete/84353/integrated Del: useless -- https://master.php.net/note/delete/84353/useless Del: bad code -- https://master.php.net/note/delete/84353/bad+code Del: spam -- https://master.php.net/note/delete/84353/spam Del: non-english -- https://master.php.net/note/delete/84353/non-english Del: in docs -- https://master.php.net/note/delete/84353/in+docs Del: other reasons-- https://master.php.net/note/delete/84353 Reject -- https://master.php.net/note/reject/84353 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#141350) next »