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 [2010/12/26 19:19]
cataphract style
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.
Line 1132: Line 1135:
   - Do post-creation initialization on the new objected (the construction phase), typically through an auxiliary function.   - Do post-creation initialization on the new objected (the construction phase), typically through an auxiliary function.
  
-For instantions ​with ''​new'':​+For instantiations ​with ''​new'':​
   - Call the class entry'​s ''​create_object''​ handler.   - Call the class entry'​s ''​create_object''​ handler.
     - (see above)     - (see above)
Line 1138: Line 1141:
   - Call the PHP constructor,​ if any. Typically, the internal implementation of the constructor delegates the construction task to the same auxiliary function referred to in the last step of the list before.   - Call the PHP constructor,​ if any. Typically, the internal implementation of the constructor delegates the construction task to the same auxiliary function referred to in the last step of the list before.
  
-Stored objects should not be destroyed explicitly; in fact, the store API doesn'​t even expose a function to destroy a particular object. Instead, the destruction should be managed through the refcount. When the reference count hits 0, the store will call the object "​destruct"​ store handler (if the object construction didn't fail) and the "free object"​ handler and remove the entry from its table. See also the ''​[[#​add_ref|add_ref]]''​ and ''​[[#​del_ref|add_ref]]''​ handlers.+Stored objects should not be destroyed explicitly; in fact, the store API doesn'​t even expose a function to destroy a particular object. Instead, the destruction should be managed through the refcount. When the reference count hits 0, the store will call the object "​destruct"​ store handler (if the object construction didn't fail) and the "free object"​ handler and remove the entry from its table. See also the ''​[[#​add_ref|add_ref]]''​ and ''​[[#​del_ref|del_ref]]''​ handlers.
  
internals/engine/objects.1293391171.txt.gz · Last modified: 2017/09/22 13:28 (external edit)