note 99274 deleted from language.oop5.constants by tularis
| From: | tularis@php.net | Date: | Sun, 04 Dec 2011 18:49:28 +0000 |
| Subject: | note 99274 deleted from language.oop5.constants by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-184886@lists.php.net to get a copy of this message | ||
Note Submitter: John Galt
----
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>";
?>