Details
-
Improvement
-
Resolution: Won't Fix
-
Medium
-
None
-
4.7.0
-
None
Description
When creating a custom class extending eZPersistentObject it is not possible to initialize an object with default values.
Example code:
class eZPersistentObjectTest extends eZPersistentObject { static public function definition() { static $definition = array( "fields" => array( "test" => array( "name" => "test", "datatype" => "string", "default" => "test", "required" => false, ), ), "class_name" => "eZPersistentObjectTest", ); return $definition; } } $test = new eZPersistentObjectTest( false ); var_dump( $test->attribute( "test" ) );
This will create the error Notice: Undefined property: eZPersistentObjectTest::$test in ezpersistentobject.php on line 1298 and return NULL.
A better approach would be to initialize the object with the defined default values, if available.
My proposal can be found here: https://github.com/ezsystems/ezpublish/pull/512