internals:engine:objects

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
internals:engine:objects [2011/03/16 10:20]
cataphract minor typos
internals:engine:objects [2017/09/22 13:28] (current)
Line 80: Line 80:
   * Called when an object is to be cloned (associated with usage of the ''​clone''​ operator in user space).   * Called when an object is to be cloned (associated with usage of the ''​clone''​ operator in user space).
   * Should return a ''​zend_object_value''​ that refers to a newly created object that is equal to the object referred to the passed reference. The two objects should not be identical, i.e., ''​==''​ applied to the references should return ''​true''​ but ''​===''​ should return ''​false''​. The ''​[[#​compare_objects|compare_objects]]''​ handlers must be the same since that is a requisite for ''​==''​ returning ''​true'',​ but typically, as one would want the two objects to have identical behavior, they ought to share all the handlers.   * Should return a ''​zend_object_value''​ that refers to a newly created object that is equal to the object referred to the passed reference. The two objects should not be identical, i.e., ''​==''​ applied to the references should return ''​true''​ but ''​===''​ should return ''​false''​. The ''​[[#​compare_objects|compare_objects]]''​ handlers must be the same since that is a requisite for ''​==''​ returning ''​true'',​ but typically, as one would want the two objects to have identical behavior, they ought to share all the handlers.
 +  * Zend standard object extensions can call ''​zend_objects_clone_members''​ to copy properties; this function also calls the class entry ''​clone''​ function (typically ''​%%__clone%%''​).
   * The created object should be initialized as if it had one reference.   * The created object should be initialized as if it had one reference.
   * May be ''​NULL''​ to forbid cloning.   * May be ''​NULL''​ to forbid cloning.
Line 909: Line 910:
  
 However, this is by far a more popular approach, since it's simple and portable -- it uses only stable parts of the API. However, this is by far a more popular approach, since it's simple and portable -- it uses only stable parts of the API.
 +
 +A variant of this strategy is to centralize the object state validation in the ''​[[#​get_method|get_method]]''​ handler and either throw a fatal error or return a method that throws an exception from the handler in case the object state is invalid. This makes it easier to fix current code without replacing the calls to ''​zend_object_store_get_object''​ in every method implementation.
  
 Finally, another option, certainly less complex but more limiting, is to make the superclass constructor final. Finally, another option, certainly less complex but more limiting, is to make the superclass constructor final.
internals/engine/objects.1300270834.txt.gz · Last modified: 2017/09/22 13:28 (external edit)