Permalink
Browse files

Closure object cannot have properties

  • Loading branch information...
1 parent 05d2ae4 commit 4d8bdd9d1b8a0287ec34f4baca527dbd32103722 Dmitry Stogov committed Jul 22, 2008
Showing with 53 additions and 0 deletions.
  1. +12 −0 Zend/tests/closure_022.phpt
  2. +41 −0 Zend/zend_closures.c
@@ -0,0 +1,12 @@
+--TEST--
+Closure 022: Closure properties
+--FILE--
+<?php
+$a = 0;
+$foo = function() use ($a) {
+};
+$foo->a = 1;
+?>
+--EXPECTF--
+Fatal error: Closure object cannot have properties in %sclosure_022.php on line 5
+
View
@@ -29,6 +29,9 @@
#define ZEND_INVOKE_FUNC_NAME "__invoke"
#define ZEND_CLOSURE_PRINT_NAME "Closure object"
+#define ZEND_CLOSURE_PROPERTY_ERROR() \
+ zend_error(E_ERROR, "Closure object cannot have properties")
+
typedef struct _zend_closure {
zend_object std;
zend_function func;
@@ -137,6 +140,39 @@ static zend_function *zend_closure_get_method(zval **object_ptr, char *method_na
}
/* }}} */
+static zval *zend_closure_read_property(zval *object, zval *member, int type TSRMLS_DC) /* {{{ */
+{
+ ZEND_CLOSURE_PROPERTY_ERROR();
+ return NULL;
+}
+/* }}} */
+
+static void zend_closure_write_property(zval *object, zval *member, zval *value TSRMLS_DC) /* {{{ */
+{
+ ZEND_CLOSURE_PROPERTY_ERROR();
+}
+/* }}} */
+
+static zval **zend_closure_get_property_ptr_ptr(zval *object, zval *member TSRMLS_DC) /* {{{ */
+{
+ ZEND_CLOSURE_PROPERTY_ERROR();
+ return NULL;
+}
+/* }}} */
+
+static int zend_closure_has_property(zval *object, zval *member, int has_set_exists TSRMLS_DC) /* {{{ */
+{
+ ZEND_CLOSURE_PROPERTY_ERROR();
+ return 0;
+}
+/* }}} */
+
+static void zend_closure_unset_property(zval *object, zval *member TSRMLS_DC) /* {{{ */
+{
+ ZEND_CLOSURE_PROPERTY_ERROR();
+}
+/* }}} */
+
static void zend_closure_free_storage(void *object TSRMLS_DC) /* {{{ */
{
zend_closure *closure = (zend_closure *)object;
@@ -195,6 +231,11 @@ void zend_register_closure_ce(TSRMLS_D) /* {{{ */
memcpy(&closure_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
closure_handlers.get_constructor = zend_closure_get_constructor;
closure_handlers.get_method = zend_closure_get_method;
+ closure_handlers.write_property = zend_closure_write_property;
+ closure_handlers.read_property = zend_closure_read_property;
+ closure_handlers.get_property_ptr_ptr = zend_closure_get_property_ptr_ptr;
+ closure_handlers.has_property = zend_closure_has_property;
+ closure_handlers.unset_property = zend_closure_unset_property;
closure_handlers.compare_objects = zend_closure_compare_objects;
closure_handlers.cast_object = zend_closure_cast_object_tostring;
closure_handlers.clone_obj = NULL;

0 comments on commit 4d8bdd9

Please sign in to comment.