note 118998 modified in language.oop5.constants by cmb

From: Date: Tue, 15 Mar 2016 09:27:30 +0000
Subject: note 118998 modified in language.oop5.constants by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-205166@lists.php.net to get a copy of this message
[Editor's note: that is already possible as of PHP 5.6.0.] Note, as of PHP7 it is possible to define class constants with an array. <?php class MyClass { const ABC = array('A', 'B', 'C'); const A = '1'; const B = '2'; const C = '3'; const NUMBERS = array( self::A, self::B, self::C, ); } var_dump(MyClass::ABC); var_dump(MyClass::NUMBERS); // Result: /* array(3) { [0]=> string(1) "A" [1]=> string(1) "B" [2]=> string(1) "C" } array(3) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "3" } */ ?> --was-- Note, as of PHP7 it is possible to define class constants with an array. <?php class MyClass { const ABC = array('A', 'B', 'C'); const A = '1'; const B = '2'; const C = '3'; const NUMBERS = array( self::A, self::B, self::C, ); } var_dump(MyClass::ABC); var_dump(MyClass::NUMBERS); // Result: /* array(3) { [0]=> string(1) "A" [1]=> string(1) "B" [2]=> string(1) "C" } array(3) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "3" } */ ?> http://php.net/manual/en/language.oop5.constants.php

« previous php.notes (#205166) next »