php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
incomplete_class.c
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Author: Sascha Schumann <sascha@schumann.cx> |
14 +----------------------------------------------------------------------+
15*/
16
17#include "php.h"
18#include "basic_functions.h"
20
21#define INCOMPLETE_CLASS_MSG \
22 "The script tried to %s on an incomplete object. " \
23 "Please ensure that the class definition \"%s\" of the object " \
24 "you are trying to operate on was loaded _before_ " \
25 "unserialize() gets called or provide an autoloader " \
26 "to load the class definition"
27
29static zend_object_handlers php_incomplete_object_handlers;
30
31static void incomplete_class_message(zend_object *object)
32{
33 zend_string *class_name = php_lookup_class_name(object);
35 "access a property", class_name ? ZSTR_VAL(class_name) : "unknown");
36 if (class_name) {
37 zend_string_release_ex(class_name, 0);
38 }
39}
40
41static void throw_incomplete_class_error(zend_object *object, const char *what)
42{
43 zend_string *class_name = php_lookup_class_name(object);
45 what, class_name ? ZSTR_VAL(class_name) : "unknown");
46 if (class_name) {
47 zend_string_release_ex(class_name, 0);
48 }
49}
50
51static zval *incomplete_class_get_property(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv) /* {{{ */
52{
53 incomplete_class_message(object);
54
55 if (type == BP_VAR_W || type == BP_VAR_RW) {
57 return rv;
58 } else {
59 return &EG(uninitialized_zval);
60 }
61}
62/* }}} */
63
64static zval *incomplete_class_write_property(zend_object *object, zend_string *member, zval *value, void **cache_slot) /* {{{ */
65{
66 throw_incomplete_class_error(object, "modify a property");
67 return value;
68}
69/* }}} */
70
71static zval *incomplete_class_get_property_ptr_ptr(zend_object *object, zend_string *member, int type, void **cache_slot) /* {{{ */
72{
73 throw_incomplete_class_error(object, "modify a property");
74 return &EG(error_zval);
75}
76/* }}} */
77
78static void incomplete_class_unset_property(zend_object *object, zend_string *member, void **cache_slot) /* {{{ */
79{
80 throw_incomplete_class_error(object, "modify a property");
81}
82/* }}} */
83
84static int incomplete_class_has_property(zend_object *object, zend_string *member, int check_empty, void **cache_slot) /* {{{ */
85{
86 incomplete_class_message(object);
87 return 0;
88}
89/* }}} */
90
91static zend_function *incomplete_class_get_method(zend_object **object, zend_string *method, const zval *key) /* {{{ */
92{
93 throw_incomplete_class_error(*object, "call a method");
94 return NULL;
95}
96/* }}} */
97
98/* {{{ php_create_incomplete_class */
99static zend_object *php_create_incomplete_object(zend_class_entry *class_type)
100{
102
103 object = zend_objects_new( class_type);
104 object->handlers = &php_incomplete_object_handlers;
105
106 object_properties_init(object, class_type);
107
108 return object;
109}
110
112{
113 memcpy(&php_incomplete_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
114 php_incomplete_object_handlers.read_property = incomplete_class_get_property;
115 php_incomplete_object_handlers.has_property = incomplete_class_has_property;
116 php_incomplete_object_handlers.unset_property = incomplete_class_unset_property;
117 php_incomplete_object_handlers.write_property = incomplete_class_write_property;
118 php_incomplete_object_handlers.get_property_ptr_ptr = incomplete_class_get_property_ptr_ptr;
119 php_incomplete_object_handlers.get_method = incomplete_class_get_method;
120
121 php_ce_incomplete_class->create_object = php_create_incomplete_object;
122}
123/* }}} */
124
125/* {{{ php_lookup_class_name */
127{
128 if (object->properties) {
129 zval *val = zend_hash_str_find(object->properties, MAGIC_MEMBER, sizeof(MAGIC_MEMBER)-1);
130
131 if (val != NULL && Z_TYPE_P(val) == IS_STRING) {
132 return zend_string_copy(Z_STR_P(val));
133 }
134 }
135
136 return NULL;
137}
138/* }}} */
139
140/* {{{ php_store_class_name */
148/* }}} */
php_ce_incomplete_class
zend_ffi_type * type
Definition ffi.c:3812
memcpy(ptr1, ptr2, size)
zval * val
Definition ffi.c:4262
#define NULL
Definition gdcache.h:45
PHPAPI zend_string * php_lookup_class_name(zend_object *object)
PHPAPI void php_register_incomplete_class_handlers(void)
PHPAPI void php_store_class_name(zval *object, zend_string *name)
#define INCOMPLETE_CLASS_MSG
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
Definition main.c:1173
#define PHPAPI
Definition php.h:71
#define MAGIC_MEMBER
unsigned char key[REFLECTION_KEY_LEN]
zval rv
Definition session.c:1024
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format,...)
Definition zend.c:1772
ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type)
Definition zend_API.c:1688
struct _zval_struct zval
zend_string_release_ex(func->internal_function.function_name, 0)
#define BP_VAR_W
#define BP_VAR_RW
#define E_WARNING
Definition zend_errors.h:24
union _zend_function zend_function
#define EG(v)
ZEND_API zval *ZEND_FASTCALL zend_hash_str_find(const HashTable *ht, const char *str, size_t len)
Definition zend_hash.c:2689
ZEND_API zval *ZEND_FASTCALL zend_hash_str_update(HashTable *ht, const char *str, size_t len, zval *pData)
Definition zend_hash.c:1031
struct _zend_string zend_string
ZEND_API const zend_object_handlers std_object_handlers
ZEND_API zend_object *ZEND_FASTCALL zend_objects_new(zend_class_entry *ce)
struct _zend_class_entry zend_class_entry
struct _zend_object zend_object
#define ZSTR_VAL(zstr)
Definition zend_string.h:68
#define Z_TYPE_P(zval_p)
Definition zend_types.h:660
#define IS_STRING
Definition zend_types.h:606
#define ZVAL_STR_COPY(z, s)
#define Z_STR_P(zval_p)
Definition zend_types.h:972
#define Z_OBJPROP_P(zval_p)
struct _zend_object_handlers zend_object_handlers
Definition zend_types.h:88
#define ZVAL_ERROR(z)
zend_string * name
object
value