note 71077 added to language.oop5.constants

From: Date: Fri, 10 Nov 2006 21:32:04 +0000
Subject: note 71077 added to language.oop5.constants
Groups: php.notes 
Request: Send a blank email to php-notes+get-119595@lists.php.net to get a copy of this message
In response to anon on 31-May-2006 02:03: If you can define a global constant based on the return of a function, please explain why you do not see it justifiable that a class constant should be able to be assigned in the same manner. This affects ALL members of a class, not just constants and, for the sake of class constants, I see this as quite severe limitation to PHP. Take the following class for example: <?php class parser { private $magic_quotes = false; public function __construct() { $this->magic_quotes = (bool)get_magic_quotes_gpc(); } public my_stripslashes( $str ) { if( $this->magic_quotes ) { $str = stripslashes( $str ); } return $str; } } ?> Wouldn't this be much cleaner and easier to impliment like this? <?php class parser { const magic_quotes = (bool)get_magic_quotes_gpc(); public my_stripslashes( $str ) { if( self::magic_quotes_gpc ) { $str = stripslashes( $str ); } return $str; } } ?> In the second iteration, there isn't a need to scour through the script to find where magic_quotes is assigned a value and there is no confusion as to EXACTLY what magic_quotes is. More so, there is no worry that some silly end user will be able to change the value of magic_quotes in any of their "modifications" to your code as constants are a read only property. Personally I find this practical for script operation., but completely impossible in PHP. ---- Server IP: 64.71.164.2 Probable Submitter: 71.231.101.38 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.constants.php Edit -- https://master.php.net/note/edit/71077 Del: integrated -- https://master.php.net/note/delete/71077/integrated Del: useless -- https://master.php.net/note/delete/71077/useless Del: bad code -- https://master.php.net/note/delete/71077/bad+code Del: spam -- https://master.php.net/note/delete/71077/spam Del: non-english -- https://master.php.net/note/delete/71077/non-english Del: in docs -- https://master.php.net/note/delete/71077/in+docs Del: other reasons-- https://master.php.net/note/delete/71077 Reject -- https://master.php.net/note/reject/71077 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#119595) next »