note 126937 deleted from language.constants by danbrown

From: Date: Sun, 03 Apr 2022 21:00:32 +0000
Subject: note 126937 deleted from language.constants by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218004@lists.php.net to get a copy of this message
Note Submitter: insta = @emnatkins - &*iran*& ---- for ($i=0;$i<30;$i++){ define("day", $i); echo $i; } ========================== or ========================== define("A",10); define("B",25); echo constant("A") + constant("B") ; ========================== or ========================== class A { const foo = 'bar'; } echo A::foo; ========================== or ========================== define('ANIMALS', ['dog','cat','bird']); var_dump(ANIMALS); ========================== or ========================== if (!defined('SITE_NAME')) { const SITE_NAME = "SokanAcademy"; } echo SITE_NAME; ========================== or ========================== class A { const foo = 'bar'; public function getConstant( $const ) { return constant('self::' . $const); } } $classA = new A(); // Returns bar echo $classA->getConstant( 'foo' );

« previous php.notes (#218004) next »