summaryrefslogtreecommitdiff
path: root/ext/reflection
diff options
context:
space:
mode:
Diffstat (limited to 'ext/reflection')
-rw-r--r--ext/reflection/php_reflection.c42
-rw-r--r--ext/reflection/tests/ReflectionClass_getConstructor_basic.phpt7
-rw-r--r--ext/reflection/tests/ReflectionClass_isIterateable_001.phpt28
-rw-r--r--ext/reflection/tests/ReflectionMethod_constructor_basic.phpt2
-rw-r--r--ext/reflection/tests/ReflectionObject_getConstructor_basic.phpt5
-rw-r--r--ext/reflection/tests/ReflectionParameter_isDefault.phpt34
-rw-r--r--ext/reflection/tests/bug52854.phpt28
-rw-r--r--ext/reflection/tests/bug53366.phpt25
8 files changed, 147 insertions, 24 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index a1363a943..018e26248 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -20,7 +20,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_reflection.c 300393 2010-06-11 23:37:55Z felipe $ */
+/* $Id: php_reflection.c 305605 2010-11-21 12:24:09Z johannes $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -190,7 +190,8 @@ typedef enum {
REF_TYPE_OTHER, /* Must be 0 */
REF_TYPE_FUNCTION,
REF_TYPE_PARAMETER,
- REF_TYPE_PROPERTY
+ REF_TYPE_PROPERTY,
+ REF_TYPE_DYNAMIC_PROPERTY
} reflection_type_t;
/* Struct for reflection objects */
@@ -272,6 +273,7 @@ static void reflection_free_objects_storage(void *object TSRMLS_DC)
{
reflection_object *intern = (reflection_object *) object;
parameter_reference *reference;
+ property_reference *prop_reference;
if (intern->ptr) {
switch (intern->ref_type) {
@@ -286,6 +288,11 @@ static void reflection_free_objects_storage(void *object TSRMLS_DC)
case REF_TYPE_PROPERTY:
efree(intern->ptr);
break;
+ case REF_TYPE_DYNAMIC_PROPERTY:
+ prop_reference = (property_reference*)intern->ptr;
+ efree(prop_reference->prop.name);
+ efree(intern->ptr);
+ break;
case REF_TYPE_OTHER:
break;
}
@@ -2934,6 +2941,10 @@ ZEND_METHOD(reflection_method, getDeclaringClass)
METHOD_NOTSTATIC(reflection_method_ptr);
GET_REFLECTION_OBJECT_PTR(mptr);
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
zend_reflection_class_factory(mptr->common.scope, return_value TSRMLS_CC);
}
@@ -2949,6 +2960,10 @@ ZEND_METHOD(reflection_method, getPrototype)
METHOD_NOTSTATIC(reflection_method_ptr);
GET_REFLECTION_OBJECT_PTR(mptr);
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
if (!mptr->common.prototype) {
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
"Method %s::%s does not have a prototype", intern->ce->name, mptr->common.function_name);
@@ -3575,13 +3590,15 @@ ZEND_METHOD(reflection_class, getProperty)
if (zend_hash_exists(Z_OBJ_HT_P(intern->obj)->get_properties(intern->obj TSRMLS_CC), name, name_len+1)) {
zend_property_info property_info_tmp;
property_info_tmp.flags = ZEND_ACC_IMPLICIT_PUBLIC;
- property_info_tmp.name = name;
+ property_info_tmp.name = estrndup(name, name_len);
property_info_tmp.name_length = name_len;
property_info_tmp.h = zend_get_hash_value(name, name_len+1);
property_info_tmp.doc_comment = NULL;
property_info_tmp.ce = ce;
reflection_property_factory(ce, &property_info_tmp, return_value TSRMLS_CC);
+ intern = (reflection_object *) zend_object_store_get_object(return_value TSRMLS_CC);
+ intern->ref_type = REF_TYPE_DYNAMIC_PROPERTY;
return;
}
}
@@ -3652,6 +3669,7 @@ static int _adddynproperty(zval **pptr TSRMLS_DC, int num_args, va_list args, ze
ZVAL_STRINGL(&member, hash_key->arKey, hash_key->nKeyLength-1, 0);
if (zend_get_property_info(ce, &member, 1 TSRMLS_CC) == &EG(std_property_info)) {
MAKE_STD_ZVAL(property);
+ EG(std_property_info).flags = ZEND_ACC_IMPLICIT_PUBLIC;
reflection_property_factory(ce, &EG(std_property_info), property TSRMLS_CC);
add_next_index_zval(retval, property);
}
@@ -3995,7 +4013,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs)
if (params) {
efree(params);
}
- } else if (!ZEND_NUM_ARGS()) {
+ } else if (!ZEND_NUM_ARGS() || !argc) {
object_init_ex(return_value, ce);
} else {
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name);
@@ -4174,6 +4192,10 @@ ZEND_METHOD(reflection_class, isIterateable)
{
reflection_object *intern;
zend_class_entry *ce;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
METHOD_NOTSTATIC(reflection_class_ptr);
GET_REFLECTION_OBJECT_PTR(ce);
@@ -4188,6 +4210,10 @@ ZEND_METHOD(reflection_class, getExtension)
{
reflection_object *intern;
zend_class_entry *ce;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
METHOD_NOTSTATIC(reflection_class_ptr);
GET_REFLECTION_OBJECT_PTR(ce);
@@ -4204,6 +4230,10 @@ ZEND_METHOD(reflection_class, getExtensionName)
{
reflection_object *intern;
zend_class_entry *ce;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
METHOD_NOTSTATIC(reflection_class_ptr);
GET_REFLECTION_OBJECT_PTR(ce);
@@ -5505,7 +5535,7 @@ PHP_MINFO_FUNCTION(reflection) /* {{{ */
php_info_print_table_start();
php_info_print_table_header(2, "Reflection", "enabled");
- php_info_print_table_row(2, "Version", "$Revision: 300393 $");
+ php_info_print_table_row(2, "Version", "$Revision: 305605 $");
php_info_print_table_end();
} /* }}} */
@@ -5519,7 +5549,7 @@ zend_module_entry reflection_module_entry = { /* {{{ */
NULL,
NULL,
PHP_MINFO(reflection),
- "$Revision: 300393 $",
+ "$Revision: 305605 $",
STANDARD_MODULE_PROPERTIES
}; /* }}} */
diff --git a/ext/reflection/tests/ReflectionClass_getConstructor_basic.phpt b/ext/reflection/tests/ReflectionClass_getConstructor_basic.phpt
index f3881c56d..1f5ba432c 100644
--- a/ext/reflection/tests/ReflectionClass_getConstructor_basic.phpt
+++ b/ext/reflection/tests/ReflectionClass_getConstructor_basic.phpt
@@ -64,10 +64,7 @@ foreach ($classes as $class) {
?>
--EXPECTF--
-
-Strict Standards: Redefining already defined constructor for class OldAndNewCtor in %s on line 26
-
-Strict Standards: %s for class NewAndOldCtor in %s on line 31
+Strict Standards: Redefining already defined constructor for class OldAndNewCtor in %s on line %d
Constructor of NewCtor: __construct
Constructor of ExtendsNewCtor: __construct
Constructor of OldCtor: OldCtor
@@ -79,4 +76,4 @@ Constructor of C: C
Constructor of D1: __construct
Constructor of D2: C
No constructor for X
-No constructor for Y \ No newline at end of file
+No constructor for Y
diff --git a/ext/reflection/tests/ReflectionClass_isIterateable_001.phpt b/ext/reflection/tests/ReflectionClass_isIterateable_001.phpt
index 3ece91542..4936413ef 100644
--- a/ext/reflection/tests/ReflectionClass_isIterateable_001.phpt
+++ b/ext/reflection/tests/ReflectionClass_isIterateable_001.phpt
@@ -62,13 +62,27 @@ Is ExtendsIteratorAggregateImpl iterable? bool(true)
Is A iterable? bool(false)
Test invalid params:
-bool(true)
-bool(true)
-bool(true)
-bool(true)
-bool(true)
-bool(true)
-bool(true)
+
+Warning: ReflectionClass::isIterateable() expects exactly 0 parameters, 1 given in %s on line 34
+NULL
+
+Warning: ReflectionClass::isIterateable() expects exactly 0 parameters, 2 given in %s on line 35
+NULL
+
+Warning: ReflectionClass::isIterateable() expects exactly 0 parameters, 1 given in %s on line 36
+NULL
+
+Warning: ReflectionClass::isIterateable() expects exactly 0 parameters, 1 given in %s on line 37
+NULL
+
+Warning: ReflectionClass::isIterateable() expects exactly 0 parameters, 1 given in %s on line 38
+NULL
+
+Warning: ReflectionClass::isIterateable() expects exactly 0 parameters, 1 given in %s on line 39
+NULL
+
+Warning: ReflectionClass::isIterateable() expects exactly 0 parameters, 1 given in %s on line 40
+NULL
Test static invocation:
diff --git a/ext/reflection/tests/ReflectionMethod_constructor_basic.phpt b/ext/reflection/tests/ReflectionMethod_constructor_basic.phpt
index dcc6080b4..2a2f02ffe 100644
--- a/ext/reflection/tests/ReflectionMethod_constructor_basic.phpt
+++ b/ext/reflection/tests/ReflectionMethod_constructor_basic.phpt
@@ -86,8 +86,6 @@ var_dump($methodInfo->isConstructor());
?>
--EXPECTF--
Strict Standards: Redefining already defined constructor for class OldAndNewCtor in %s on line %d
-
-Strict Standards: %s for class NewAndOldCtor in %s on line %d
New-style constructor:
bool(true)
diff --git a/ext/reflection/tests/ReflectionObject_getConstructor_basic.phpt b/ext/reflection/tests/ReflectionObject_getConstructor_basic.phpt
index a784f6d9e..5a0c36f9e 100644
--- a/ext/reflection/tests/ReflectionObject_getConstructor_basic.phpt
+++ b/ext/reflection/tests/ReflectionObject_getConstructor_basic.phpt
@@ -64,10 +64,7 @@ foreach ($classes as $class) {
?>
--EXPECTF--
-
-Strict Standards: Redefining already defined constructor for class OldAndNewCtor in %s on line 26
-
-Strict Standards: %s for class NewAndOldCtor in %s on line 31
+Strict Standards: Redefining already defined constructor for class OldAndNewCtor in %s on line %d
Constructor of NewCtor: __construct
Constructor of ExtendsNewCtor: __construct
Constructor of OldCtor: OldCtor
diff --git a/ext/reflection/tests/ReflectionParameter_isDefault.phpt b/ext/reflection/tests/ReflectionParameter_isDefault.phpt
new file mode 100644
index 000000000..657077093
--- /dev/null
+++ b/ext/reflection/tests/ReflectionParameter_isDefault.phpt
@@ -0,0 +1,34 @@
+--TEST--
+ReflectionParameter::isDefault()
+--FILE--
+<?php
+class A {
+public $defprop;
+}
+$a = new A;
+$a->myprop = null;
+
+$ro = new ReflectionObject($a);
+$props = $ro->getProperties();
+$prop1 = $props[0];
+var_dump($prop1->isDefault());
+$prop2 = $props[1];
+var_dump($prop2->isDefault());
+
+var_dump($ro->getProperty('defprop')->isDefault());
+var_dump($ro->getProperty('myprop')->isDefault());
+
+$prop1 = new ReflectionProperty($a, 'defprop');
+$prop2 = new ReflectionProperty($a, 'myprop');
+var_dump($prop1->isDefault());
+var_dump($prop2->isDefault());
+?>
+==DONE==
+--EXPECT--
+bool(true)
+bool(false)
+bool(true)
+bool(false)
+bool(true)
+bool(false)
+==DONE==
diff --git a/ext/reflection/tests/bug52854.phpt b/ext/reflection/tests/bug52854.phpt
new file mode 100644
index 000000000..255522de5
--- /dev/null
+++ b/ext/reflection/tests/bug52854.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Bug #52854: ReflectionClass::newInstanceArgs does not work for classes without constructors
+--FILE--
+<?php
+class Test {
+}
+$c = new ReflectionClass('Test');
+var_dump(new Test);
+var_dump(new Test());
+var_dump($c->newInstance());
+var_dump($c->newInstanceArgs(array()));
+
+try {
+ var_dump($c->newInstanceArgs(array(1)));
+} catch(ReflectionException $e) {
+ echo $e->getMessage()."\n";
+}
+?>
+--EXPECTF--
+object(Test)#%d (0) {
+}
+object(Test)#%d (0) {
+}
+object(Test)#%d (0) {
+}
+object(Test)#%d (0) {
+}
+Class Test does not have a constructor, so you cannot pass any constructor arguments
diff --git a/ext/reflection/tests/bug53366.phpt b/ext/reflection/tests/bug53366.phpt
new file mode 100644
index 000000000..5fb119d82
--- /dev/null
+++ b/ext/reflection/tests/bug53366.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Bug #53366 (Reflection doesnt get dynamic property value from getProperty())
+--FILE--
+<?php
+
+class UserClass {
+}
+
+$myClass = new UserClass;
+$myClass->id = 1000;
+
+$reflect = new ReflectionObject($myClass);
+
+var_dump($reflect->getProperty('id'));
+var_dump($reflect->getProperty('id')->getValue($myClass));
+
+?>
+--EXPECTF--
+object(ReflectionProperty)#%d (2) {
+ ["name"]=>
+ string(2) "id"
+ ["class"]=>
+ string(9) "UserClass"
+}
+int(1000)