make &$this->headers work; &$this->headers["foo"] still doesn't though
authorMichael Wallner <mike@php.net>
Sat, 14 Jan 2012 10:55:48 +0000 (10:55 +0000)
committerMichael Wallner <mike@php.net>
Sat, 14 Jan 2012 10:55:48 +0000 (10:55 +0000)
php_http_message.c
php_http_property_proxy.c

index d6a7f755c76b73e0b6a6719f5ac1d42b80d222b1..066deca86566b3e640d6e92e0d9ab2f112e39c49 100644 (file)
@@ -1153,18 +1153,16 @@ static zval *php_http_message_object_read_prop(zval *object, zval *member, int t
        zval *return_value, *copy = php_http_ztyp(IS_STRING, member);
 
        if (SUCCESS == php_http_message_object_get_prophandler(Z_STRVAL_P(copy), Z_STRLEN_P(copy), &handler)) {
-               if (type == BP_VAR_W) {
-                       zval_ptr_dtor(&copy);
+               if (type == BP_VAR_R) {
+                       ALLOC_ZVAL(return_value);
+                       Z_SET_REFCOUNT_P(return_value, 0);
+                       Z_UNSET_ISREF_P(return_value);
+
+                       handler->read(obj, return_value TSRMLS_CC);
+               } else {
                        zend_error(E_ERROR, "Cannot access HttpMessage properties by reference or array key/index");
-                       return NULL;
+                       return_value = NULL;
                }
-
-               ALLOC_ZVAL(return_value);
-               Z_SET_REFCOUNT_P(return_value, 0);
-               Z_UNSET_ISREF_P(return_value);
-
-               handler->read(obj, return_value TSRMLS_CC);
-
        } else {
                return_value = zend_get_std_object_handlers()->read_property(object, member, type, literal_key TSRMLS_CC);
        }
index fc75f6daeb511298c156eabe2c7b2a92b4e265b0..8fae2f115d9eead34d0aa1fc629bd75181f90dbf 100644 (file)
 
 #include "php_http_api.h"
 
+#ifndef PHP_HTTP_PPDBG
+#      define PHP_HTTP_PPDBG 1
+#endif
+
 php_http_property_proxy_t *php_http_property_proxy_init(php_http_property_proxy_t *proxy, zval *object, zval *member TSRMLS_DC)
 {
        if (!proxy) {
@@ -25,6 +29,9 @@ php_http_property_proxy_t *php_http_property_proxy_init(php_http_property_proxy_
        proxy->object = object;
        proxy->member = php_http_ztyp(IS_STRING, member);
 
+#if PHP_HTTP_PPDBG
+       fprintf(stderr, "proxy_init: %s\n", Z_STRVAL_P(proxy->member));
+#endif
        return proxy;
 }
 
@@ -98,14 +105,43 @@ static void php_http_property_proxy_object_set(zval **object, zval *value TSRMLS
 {
        php_http_property_proxy_object_t *obj = zend_object_store_get_object(*object TSRMLS_CC);
 
-       zend_update_property(Z_OBJCE_P(obj->proxy->object), obj->proxy->object, Z_STRVAL_P(obj->proxy->member), Z_STRLEN_P(obj->proxy->member), value TSRMLS_CC);
+#if PHP_HTTP_PPDBG
+       fprintf(stderr, "proxy_set: %s\n", Z_STRVAL_P(obj->proxy->member));
+#endif
+       if (Z_TYPE_P(obj->proxy->object) == IS_OBJECT) {
+               zend_update_property(Z_OBJCE_P(obj->proxy->object), obj->proxy->object, Z_STRVAL_P(obj->proxy->member), Z_STRLEN_P(obj->proxy->member), value TSRMLS_CC);
+       } else {
+               Z_ADDREF_P(value);
+               zend_symtable_update(Z_ARRVAL_P(obj->proxy->object), Z_STRVAL_P(obj->proxy->member), Z_STRLEN_P(obj->proxy->member)+1, (void *) &value, sizeof(zval *), NULL);
+       }
 }
 
 static zval *php_http_property_proxy_object_get(zval *object TSRMLS_DC)
 {
        php_http_property_proxy_object_t *obj = zend_object_store_get_object(object TSRMLS_CC);
 
-       return zend_read_property(Z_OBJCE_P(obj->proxy->object), obj->proxy->object, Z_STRVAL_P(obj->proxy->member), Z_STRLEN_P(obj->proxy->member), 0 TSRMLS_CC);
+#if PHP_HTTP_PPDBG
+       fprintf(stderr, "proxy_get: %s\n", Z_STRVAL_P(obj->proxy->member));
+#endif
+       if (Z_TYPE_P(obj->proxy->object) == IS_OBJECT) {
+               return zend_read_property(Z_OBJCE_P(obj->proxy->object), obj->proxy->object, Z_STRVAL_P(obj->proxy->member), Z_STRLEN_P(obj->proxy->member), 0 TSRMLS_CC);
+       } else {
+               zval **data = NULL;
+
+               if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(obj->proxy->object), Z_STRVAL_P(obj->proxy->member), Z_STRLEN_P(obj->proxy->member)+1, (void *) &data)) {
+                       Z_ADDREF_PP(data);
+               } else {
+                       zval *unset;
+
+                       MAKE_STD_ZVAL(unset);
+                       ZVAL_NULL(unset);
+                       zend_symtable_update(Z_ARRVAL_P(obj->proxy->object), Z_STRVAL_P(obj->proxy->member), Z_STRLEN_P(obj->proxy->member)+1, (void *) &unset, sizeof(zval *), (void *) &data);
+               }
+
+               return *data;
+       }
+
+       return NULL;
 }
 
 static STATUS php_http_property_proxy_object_cast(zval *object, zval *return_value, int type TSRMLS_DC)
@@ -128,7 +164,16 @@ static zval *php_http_property_proxy_object_read_dimension(zval *object, zval *o
 {
        zval *retval = NULL, *property = php_http_property_proxy_object_get(object TSRMLS_CC);
 
-       if (Z_TYPE_P(property) == IS_ARRAY) {
+#if PHP_HTTP_PPDBG
+       php_http_property_proxy_object_t *obj = zend_object_store_get_object(object TSRMLS_CC);
+       zval *ocpy = php_http_ztyp(IS_STRING, offset);
+       fprintf(stderr, "read_dimension: %s.%s (%d)\n", Z_STRVAL_P(obj->proxy->member), Z_STRVAL_P(ocpy), type);
+       zval_ptr_dtor(&ocpy);
+#endif
+       if (type != BP_VAR_R) {
+               Z_ADDREF_P(property);
+               retval = php_http_property_proxy_init(NULL, property, offset TSRMLS_CC)->myself;
+       } else if (Z_TYPE_P(property) == IS_ARRAY) {
                zval **data = NULL;
 
                if (Z_TYPE_P(offset) == IS_LONG) {
@@ -148,7 +193,7 @@ static zval *php_http_property_proxy_object_read_dimension(zval *object, zval *o
                }
        }
        zval_ptr_dtor(&property);
-
+if(retval)Z_SET_ISREF_P(retval);
        return retval;
 }
 
@@ -156,6 +201,12 @@ static void php_http_property_proxy_object_write_dimension(zval *object, zval *o
 {
        zval *property = php_http_property_proxy_object_get(object TSRMLS_CC);
 
+#if PHP_HTTP_PPDBG
+       php_http_property_proxy_object_t *obj = zend_object_store_get_object(object TSRMLS_CC);
+       zval *ocpy = offset ? php_http_ztyp(IS_STRING, offset) : offset;
+       fprintf(stderr, "write_dimension: %s.%s (%d)\n", Z_STRVAL_P(obj->proxy->member), ocpy?Z_STRVAL_P(ocpy):"", Z_TYPE_P(property));
+       if(ocpy)zval_ptr_dtor(&ocpy);
+#endif
        switch (Z_TYPE_P(property)) {
                case IS_NULL:
                        array_init(property);