Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce get_properties_for() handler
This handler allows getting the object properties for a particular purpose, such as array casting, serialization, etc.
- Loading branch information
Showing
10 changed files
with
136 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,26 @@ typedef HashTable *(*zend_object_get_properties_t)(zval *object); | |
|
||
typedef HashTable *(*zend_object_get_debug_info_t)(zval *object, int *is_temp); | ||
|
||
typedef enum _zend_prop_purpose { | ||
/* Used for debugging. Supersedes get_debug_info handler. */ | ||
ZEND_PROP_PURPOSE_DEBUG, | ||
/* Used for (array) casts. */ | ||
ZEND_PROP_PURPOSE_ARRAY_CAST, | ||
/* Used for serialization using the "O" scheme. | ||
* Unserialization will use __wakeup(). */ | ||
ZEND_PROP_PURPOSE_SERIALIZE, | ||
/* Used for var_export(). | ||
* The data will be passed to __set_state() when evaluated. */ | ||
ZEND_PROP_PURPOSE_VAR_EXPORT, | ||
/* Used for json_encode(). */ | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
nikic
Author
Member
|
||
ZEND_PROP_PURPOSE_JSON, | ||
/* Dummy member to ensure that "default" is specified. */ | ||
_ZEND_PROP_PURPOSE_NON_EXHAUSTIVE_ENUM | ||
} zend_prop_purpose; | ||
|
||
/* The return value must be released using zend_release_properties(). */ | ||
typedef zend_array *(*zend_object_get_properties_for_t)(zval *object, zend_prop_purpose purpose); | ||
|
||
/* Used to call methods */ | ||
/* args on stack! */ | ||
/* Andi - EX(fbc) (function being called) needs to be initialized already in the INIT fcall opcode so that the parameters can be parsed the right way. We need to add another callback for this. | ||
|
@@ -160,6 +180,7 @@ struct _zend_object_handlers { | |
zend_object_get_gc_t get_gc; | ||
zend_object_do_operation_t do_operation; | ||
zend_object_compare_zvals_t compare; | ||
zend_object_get_properties_for_t get_properties_for; /* optional */ | ||
}; | ||
|
||
BEGIN_EXTERN_C() | ||
|
@@ -207,6 +228,20 @@ ZEND_API zend_function *zend_get_call_trampoline_func(zend_class_entry *ce, zend | |
|
||
ZEND_API uint32_t *zend_get_property_guard(zend_object *zobj, zend_string *member); | ||
|
||
/* Default behavior for get_properties_for. For use as a fallback in custom | ||
* get_properties_for implementations. */ | ||
ZEND_API HashTable *zend_std_get_properties_for(zval *obj, zend_prop_purpose purpose); | ||
|
||
/* Will call get_properties_for handler or use default behavior. For use by | ||
* consumers of the get_properties_for API. */ | ||
ZEND_API HashTable *zend_get_properties_for(zval *obj, zend_prop_purpose purpose); | ||
|
||
#define zend_release_properties(ht) do { \ | ||
if ((ht) && !(GC_FLAGS(ht) & GC_IMMUTABLE) && !GC_DELREF(ht)) { \ | ||
zend_array_destroy(ht); \ | ||
} \ | ||
} while (0) | ||
|
||
#define zend_free_trampoline(func) do { \ | ||
if ((func) == &EG(trampoline)) { \ | ||
EG(trampoline).common.function_name = NULL; \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
@nikic Does engine need to have a special case for
json_encode
? It seems identical to export so maybe something a bit more generic would be a bit cleaner.