note 55187 added to language.oop5.constants

From: Date: Wed, 27 Jul 2005 10:28:10 +0000
Subject: note 55187 added to language.oop5.constants
Groups: php.notes 
Request: Send a blank email to php-notes+get-92544@lists.php.net to get a copy of this message
I'm not sure if this is a bug or a feature, but you can't use class constants to set default values for class properties. You can, however, use them for default values for method params, e.g.: class foo {} const BAR = 100; private $thing = self::BAR; function wibble($a = self::BAR) { echo $a; } } In this case $this->thing will be undefined, but wibble() will get the correct default value for $a. ---- Manual Page -- http://www.php.net/manual/en/language.oop5.constants.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55187 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55187&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55187&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55187&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55187&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55187&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55187&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55187&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92544) next »