cvs: ZendEngine2 / zend_reflection_api.c
| From: | Marcus Boerger | Date: | Mon, 27 Sep 2004 22:24:57 +0000 |
| Subject: | cvs: ZendEngine2 / zend_reflection_api.c | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-3049@lists.php.net to get a copy of this message | ||
helly Mon Sep 27 18:24:57 2004 EDT
Modified files:
/ZendEngine2 zend_reflection_api.c
Log:
- Make internally used properties read-only and fix default properties
http://cvs.php.net/diff.php/ZendEngine2/zend_reflection_api.c?r1=1.129&r2=1.130&ty=u
Index: ZendEngine2/zend_reflection_api.c
diff -u ZendEngine2/zend_reflection_api.c:1.129 ZendEngine2/zend_reflection_api.c:1.130
--- ZendEngine2/zend_reflection_api.c:1.129 Mon Sep 27 17:25:12 2004
+++ ZendEngine2/zend_reflection_api.c Mon Sep 27 18:24:57 2004
@@ -19,7 +19,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_reflection_api.c,v 1.129 2004/09/27 21:25:12 helly Exp $ */
+/* $Id: zend_reflection_api.c,v 1.130 2004/09/27 22:24:57 helly Exp $ */
#include "zend.h"
#include "zend_API.h"
#include "zend_exceptions.h"
@@ -216,6 +216,7 @@
static zend_object_value reflection_objects_new(zend_class_entry *class_type TSRMLS_DC)
{
+ zval tmp;
zend_object_value retval;
reflection_object *intern;
@@ -229,6 +230,7 @@
ALLOC_HASHTABLE(intern->zo.properties);
zend_hash_init(intern->zo.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
+ zend_hash_copy(intern->zo.properties, &class_type->default_properties,
(copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
retval.handle = zend_objects_store_put(intern, NULL, reflection_free_objects_storage,
reflection_objects_clone TSRMLS_CC);
retval.handlers = &reflection_object_handlers;
return retval;
@@ -3525,12 +3527,33 @@
};
/* }}} */
+static zend_object_handlers *zend_std_obj_handlers;
+
+/* {{{ _reflection_write_property */
+static void _reflection_write_property(zval *object, zval *member, zval *value TSRMLS_DC)
+{
+ if (Z_TYPE_P(member) == IS_STRING
+ && zend_hash_exists(&Z_OBJCE_P(object)->default_properties, Z_STRVAL_P(member),
Z_STRLEN_P(member)+1)
+ && (!strcmp(Z_STRVAL_P(member), "name") || !strcmp(Z_STRVAL_P(member),
"class")))
+ {
+ zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
+ "Cannot set read-only property %s::$%s", Z_OBJCE_P(object)->name,
Z_STRVAL_P(member));
+ }
+ else
+ {
+ zend_std_obj_handlers->write_property(object, member, value TSRMLS_CC);
+ }
+}
+/* }}} */
+
/* {{{ zend_register_reflection_api */
ZEND_API void zend_register_reflection_api(TSRMLS_D) {
zend_class_entry _reflection_entry;
+ zend_std_obj_handlers = zend_get_std_object_handlers();
memcpy(&reflection_object_handlers, zend_get_std_object_handlers(),
sizeof(zend_object_handlers));
reflection_object_handlers.clone_obj = NULL;
+ reflection_object_handlers.write_property = _reflection_write_property;
INIT_CLASS_ENTRY(_reflection_entry, "ReflectionException",
reflection_exception_functions);
reflection_exception_ptr = zend_register_internal_class_ex(&_reflection_entry,
zend_exception_get_default(), NULL TSRMLS_CC);