Skip to content

Commit

Permalink
Move to a set of handlers on the CE
Browse files Browse the repository at this point in the history
  • Loading branch information
Girgias committed Feb 6, 2024
1 parent 31d625d commit f7291a2
Show file tree
Hide file tree
Showing 27 changed files with 597 additions and 430 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,12 @@ Cannot unset offset of type %s on ArrayObject
Nested read:
Cannot access offset of type %s on ArrayObject
Nested write:
Notice: Indirect modification of overloaded element of ArrayObject has no effect in %s on line 69
Cannot access offset of type %s on ArrayObject
Nested Read-Write:
Notice: Indirect modification of overloaded element of ArrayObject has no effect in %s on line 76
Cannot access offset of type %s on ArrayObject
Nested isset():
Cannot access offset of type %s in isset or empty
Expand All @@ -150,7 +154,7 @@ Cannot access offset of type %s in isset or empty
Nested unset():
Notice: Indirect modification of overloaded element of ArrayObject has no effect in %s on line 102
Cannot unset offset of type %s on ArrayObject
Cannot access offset of type %s on ArrayObject
OUTPUT;

Expand Down
34 changes: 17 additions & 17 deletions Zend/tests/offsets/internal_handlers.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -194,63 +194,63 @@ exportObject($o);
?>
--EXPECTF--
read op
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: BP_VAR_R, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: uninitialized, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
write op
DimensionHandlersNoArrayAccess, read: false, write: true, has: false, unset: false, readType: uninitialized, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
read-write op
DimensionHandlersNoArrayAccess, read: true, write: true, has: false, unset: false, readType: BP_VAR_R, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
DimensionHandlersNoArrayAccess, read: true, write: true, has: false, unset: false, readType: uninitialized, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
isset op
DimensionHandlersNoArrayAccess, read: false, write: false, has: true, unset: false, readType: uninitialized, hasOffset: true, checkEmpty: 0, offset: 'foo'
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: uninitialized, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
empty op
DimensionHandlersNoArrayAccess, read: false, write: false, has: true, unset: false, readType: uninitialized, hasOffset: true, checkEmpty: 1, offset: 'foo'
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: uninitialized, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
null coalescing op
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: BP_VAR_IS, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: uninitialized, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
appending op
DimensionHandlersNoArrayAccess, read: false, write: true, has: false, unset: false, readType: uninitialized, hasOffset: false, checkEmpty: uninitialized, offset: uninitialized
DimensionHandlersNoArrayAccess, read: false, write: false, has: false, unset: false, readType: uninitialized, hasOffset: false, checkEmpty: uninitialized, offset: uninitialized
unset op
DimensionHandlersNoArrayAccess, read: false, write: false, has: false, unset: true, readType: uninitialized, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
nested read

Warning: Trying to access array offset on true in %s on line %d
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: BP_VAR_R, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: uninitialized, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
nested write

Notice: Indirect modification of overloaded element of DimensionHandlersNoArrayAccess has no effect in %s on line %d
Error: Cannot use a scalar value as an array
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: BP_VAR_W, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: uninitialized, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
nested write: appending then write

Notice: Indirect modification of overloaded element of DimensionHandlersNoArrayAccess has no effect in %s on line %d
Error: Cannot use a scalar value as an array
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: BP_VAR_W, hasOffset: false, checkEmpty: uninitialized, offset: uninitialized
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: uninitialized, hasOffset: false, checkEmpty: uninitialized, offset: uninitialized
nested read-write

Notice: Indirect modification of overloaded element of DimensionHandlersNoArrayAccess has no effect in %s on line %d
Error: Cannot use a scalar value as an array
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: BP_VAR_RW, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: uninitialized, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
nested read-write: appending then write

Notice: Indirect modification of overloaded element of DimensionHandlersNoArrayAccess has no effect in %s on line %d
Error: Cannot use a scalar value as an array
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: BP_VAR_RW, hasOffset: false, checkEmpty: uninitialized, offset: uninitialized
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: uninitialized, hasOffset: false, checkEmpty: uninitialized, offset: uninitialized
nested isset
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: BP_VAR_IS, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: uninitialized, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
nested empty
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: BP_VAR_IS, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: uninitialized, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
nested null coalescing
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: BP_VAR_IS, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: uninitialized, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
nested appending

Notice: Indirect modification of overloaded element of DimensionHandlersNoArrayAccess has no effect in %s on line %d
Error: Cannot use a scalar value as an array
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: BP_VAR_W, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: uninitialized, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
nested appending: appending then append

Notice: Indirect modification of overloaded element of DimensionHandlersNoArrayAccess has no effect in %s on line %d
Error: Cannot use a scalar value as an array
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: BP_VAR_W, hasOffset: false, checkEmpty: uninitialized, offset: uninitialized
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: uninitialized, hasOffset: false, checkEmpty: uninitialized, offset: uninitialized
nested unset

Notice: Indirect modification of overloaded element of DimensionHandlersNoArrayAccess has no effect in %s on line %d
Error: Cannot unset offset in a non-array variable
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: BP_VAR_UNSET, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
DimensionHandlersNoArrayAccess, read: true, write: false, has: false, unset: false, readType: uninitialized, hasOffset: true, checkEmpty: uninitialized, offset: 'foo'
4 changes: 4 additions & 0 deletions Zend/zend.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "zend_gc.h"
#include "zend_variables.h"
#include "zend_iterators.h"
#include "zend_dimension_handlers.h"
#include "zend_stream.h"
#include "zend_smart_str_public.h"
#include "zend_smart_string_public.h"
Expand Down Expand Up @@ -202,6 +203,9 @@ struct _zend_class_entry {
int (*serialize)(zval *object, unsigned char **buffer, size_t *buf_len, zend_serialize_data *data);
int (*unserialize)(zval *object, zend_class_entry *ce, const unsigned char *buf, size_t buf_len, zend_unserialize_data *data);

/* dimension handler callbacks */
zend_class_dimensions_functions *dimension_handlers;

uint32_t num_interfaces;
uint32_t num_traits;

Expand Down
1 change: 1 addition & 0 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2034,6 +2034,7 @@ ZEND_API void zend_initialize_class_data(zend_class_entry *ce, bool nullify_hand
ce->trait_precedences = NULL;
ce->serialize = NULL;
ce->unserialize = NULL;
ce->dimension_handlers = NULL;
if (ce->type == ZEND_INTERNAL_CLASS) {
ce->info.internal.module = NULL;
ce->info.internal.builtin_functions = NULL;
Expand Down
30 changes: 16 additions & 14 deletions Zend/zend_user_dimension.h → Zend/zend_dimension_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,22 @@
+----------------------------------------------------------------------+
*/

#include "zend_types.h"
#include "zend_compile.h"
/* This really should not be needed... */
#ifndef ZEND_DIMENSION_HANDLERS_H
#define ZEND_DIMENSION_HANDLERS_H

/*
//BEGIN_EXTERN_C()

typedef struct _zend_class_dimensions_functions {
/* rv is a slot provided by the callee that is returned */
zval *(*/* const */ read_dimension)(zend_object *object, zval *offset, zval *rv);
/* For isset() rv is NULL, for null coalesce and empty() rv is a slot provided by the callee */
zval *(*/* const */ has_dimension)(zend_object *object, zval *offset, zval *rv);
void (*/* const */ write_dimension)(zend_object *object, zval *offset, zval *value);
/* rv is a slot provided by the callee that is returned */
zval *(*/* const */ append_dimension)(zend_object *object, zval *value, zval *rv);
void (*/* const */ unset_dimension)(zend_object *object, zval *offset);
} zend_class_dimensions_functions;

typedef struct _zend_class_arrayaccess_funcs {
zend_function *zf_offsetget;
Expand All @@ -28,14 +40,4 @@ typedef struct _zend_class_arrayaccess_funcs {
zend_function *zf_offsetunset;
} zend_class_arrayaccess_funcs;

*/

BEGIN_EXTERN_C()
/* rv is a slot provided by the callee that is returned */
ZEND_API zval *zend_user_class_read_dimension(zend_object *object, zval *offset, zval *rv);
/* For isset() rv is NULL, for null coalesce and empty() rv is a slot provided by the callee */
ZEND_API zval *zend_user_class_has_dimension(zend_object *object, zval *offset, zval *rv);
ZEND_API void zend_user_class_write_dimension(zend_object *object, zval *offset, zval *value);
ZEND_API zval *zend_user_class_append_dimension(zend_object *object, zval *value, zval *rv);
ZEND_API void zend_user_class_unset_dimension(zend_object *object, zval *offset);
END_EXTERN_C()
#endif /* ZEND_DIMENSION_HANDLERS_H */
Loading

0 comments on commit f7291a2

Please sign in to comment.