Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-20161

Set default values in eZPersistentObject for attributes

    XMLWordPrintable

Details

    • Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Icon: Medium 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

      Attachments

        Activity

          People

            Unassigned Unassigned
            jgamez jgamez
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: