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

Set default values in eZPersistentObject for attributes

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Medium
    • Resolution: Won't Fix
    • Affects Version/s: 4.7.0
    • Fix Version/s: None
    • Component/s: None
    • Labels:

      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

            Assignee:
            Unassigned
            Reporter:
            jgamez Jérôme Gamez
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: