note 99274 added to language.oop5.constants
| From: | JohnGalt at osu1 dot php dot net | Date: | Sat, 07 Aug 2010 20:30:13 +0000 |
| Subject: | note 99274 added to language.oop5.constants | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171455@lists.php.net to get a copy of this message | ||
A handy workaround to create a constant that contains array data using eval():
<?php
class MyClass
{
const MY_ARR = "return array(\"A\", \"B\", \"C\",
\"D\");";
public function __construct()
{
return eval(MY_ARR);
}
}
// Test implementation
$myClass = new MyClass();
echo "<pre>";
print_r($myClass);
echo "</pre>";
?>
----
Server IP: 69.147.83.197
Probable Submitter: 72.208.240.199
----
Manual Page -- http://www.php.net/manual/en/language.oop5.constants.php
Edit -- https://master.php.net/note/edit/99274
Del: integrated -- https://master.php.net/note/delete/99274/integrated
Del: useless -- https://master.php.net/note/delete/99274/useless
Del: bad code -- https://master.php.net/note/delete/99274/bad+code
Del: spam -- https://master.php.net/note/delete/99274/spam
Del: non-english -- https://master.php.net/note/delete/99274/non-english
Del: in docs -- https://master.php.net/note/delete/99274/in+docs
Del: other reasons-- https://master.php.net/note/delete/99274
Reject -- https://master.php.net/note/reject/99274
Search -- https://master.php.net/manage/user-notes.php