cseiler Mon Aug 11 22:30:44 2008 UTC
Added files:
/php-src/ext/reflection/tests closures_003.phpt closures_004.phpt
Modified files:
/php-src/ext/reflection php_reflection.c
/php-src/ext/reflection/tests
reflectionParameter_invalidMethodInConstructor.phpt
Log:
- Fixed sefaults (tests added)
http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/php_reflection.c?r1=1.314&r2=1.315&diff_format=u
Index: php-src/ext/reflection/php_reflection.c
diff -u php-src/ext/reflection/php_reflection.c:1.314
php-src/ext/reflection/php_reflection.c:1.315
--- php-src/ext/reflection/php_reflection.c:1.314 Mon Aug 11 19:34:49 2008
+++ php-src/ext/reflection/php_reflection.c Mon Aug 11 22:30:44 2008
@@ -20,7 +20,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_reflection.c,v 1.314 2008/08/11 19:34:49 helly Exp $ */
+/* $Id: php_reflection.c,v 1.315 2008/08/11 22:30:44 cseiler Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -228,6 +228,28 @@
}
/* }}} */
+static zend_function *_copy_function(zend_function *fptr TSRMLS_DC) /* {{{ */
+{
+ if (fptr
+ && fptr->type == ZEND_INTERNAL_FUNCTION
+ && (fptr->internal_function.fn_flags &
ZEND_ACC_CALL_VIA_HANDLER) != 0)
+ {
+ zend_function *copy_fptr;
+ copy_fptr = emalloc(sizeof(zend_function));
+ memcpy(copy_fptr, fptr, sizeof(zend_function));
+ if (UG(unicode)) {
+ copy_fptr->internal_function.function_name.u =
eustrdup(fptr->internal_function.function_name.u);
+ } else {
+ copy_fptr->internal_function.function_name.s =
estrdup(fptr->internal_function.function_name.s);
+ }
+ return copy_fptr;
+ } else {
+ /* no copy needed */
+ return fptr;
+ }
+}
+/* }}} */
+
static void _free_function(zend_function *fptr TSRMLS_DC) /* {{{ */
{
if (fptr
@@ -1812,7 +1834,7 @@
zval *parameter;
ALLOC_ZVAL(parameter);
- reflection_parameter_factory(fptr, arg_info, i,
fptr->common.required_num_args, parameter TSRMLS_CC);
+ reflection_parameter_factory(_copy_function(fptr TSRMLS_CC),
arg_info, i, fptr->common.required_num_args, parameter TSRMLS_CC);
add_next_index_zval(return_value, parameter);
arg_info++;
@@ -1956,7 +1978,7 @@
} else if
(zend_u_hash_find(&ce->function_table, Z_TYPE_PP(method), lcname, lcname_len +
1, (void **) &fptr) == FAILURE) {
efree(lcname.v);
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Method %R::%R() does not
exist", Z_TYPE_PP(classref), Z_UNIVAL_PP(classref), Z_TYPE_PP(method),
Z_UNIVAL_PP(method));
+ "Method %v::%R() does not
exist", ce->name, Z_TYPE_PP(method), Z_UNIVAL_PP(method));
return;
}
efree(lcname.v);
@@ -2064,9 +2086,9 @@
GET_REFLECTION_OBJECT_PTR(param);
if (!param->fptr->common.scope) {
- reflection_function_factory(param->fptr, return_value
TSRMLS_CC);
+ reflection_function_factory(_copy_function(param->fptr
TSRMLS_CC), return_value TSRMLS_CC);
} else {
- reflection_method_factory(param->fptr->common.scope,
param->fptr, return_value TSRMLS_CC);
+ reflection_method_factory(param->fptr->common.scope,
_copy_function(param->fptr TSRMLS_CC), return_value TSRMLS_CC);
}
}
/* }}} */
@@ -2458,7 +2480,14 @@
/* Returns from this function */
}
- zend_create_closure(return_value, mptr, mptr->common.scope, obj
TSRMLS_CC);
+ /* This is an original closure object and __invoke is to be
called. */
+ if (Z_OBJCE_P(obj) == zend_ce_closure && mptr->type ==
ZEND_INTERNAL_FUNCTION &&
+ (mptr->internal_function.fn_flags &
ZEND_ACC_CALL_VIA_HANDLER) != 0)
+ {
+ RETURN_ZVAL(obj, 1, 0);
+ } else {
+ zend_create_closure(return_value, mptr,
mptr->common.scope, obj TSRMLS_CC);
+ }
}
}
/* }}} */
@@ -5394,7 +5423,7 @@
php_info_print_table_start();
php_info_print_table_header(2, "Reflection", "enabled");
- php_info_print_table_row(2, "Version", "$Id: php_reflection.c,v 1.314
2008/08/11 19:34:49 helly Exp $");
+ php_info_print_table_row(2, "Version", "$Id: php_reflection.c,v 1.315
2008/08/11 22:30:44 cseiler Exp $");
php_info_print_table_end();
} /* }}} */
http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/tests/reflectionParameter_invalidMethodInConstructor.phpt?r1=1.1&r2=1.2&diff_format=u
Index:
php-src/ext/reflection/tests/reflectionParameter_invalidMethodInConstructor.phpt
diff -u /dev/null
php-src/ext/reflection/tests/reflectionParameter_invalidMethodInConstructor.phpt:1.2
--- /dev/null Mon Aug 11 22:30:44 2008
+++
php-src/ext/reflection/tests/reflectionParameter_invalidMethodInConstructor.phpt
Mon Aug 11 22:30:44 2008
@@ -0,0 +1,31 @@
+--TEST--
+ReflectionParameter::__construct(): Invalid method as constructor
+--FILE--
+<?php
+
+// Invalid class name
+try {
+ new ReflectionParameter (array ('A', 'b'), 0);
+} catch (ReflectionException $e) { echo $e->getMessage ()."\n"; }
+
+// Invalid class method
+try {
+ new ReflectionParameter (array ('C', 'b'), 0);
+} catch (ReflectionException $e) { echo $e->getMessage ()."\n"; }
+
+// Invalid object method
+try {
+ new ReflectionParameter (array (new C, 'b'), 0);
+} catch (ReflectionException $e) { echo $e->getMessage ()."\n"; }
+
+echo "Done.\n";
+
+class C {
+}
+
+?>
+--EXPECTF--
+Class A does not exist
+Method C::b() does not exist
+Method C::b() does not exist
+Done.
http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/tests/closures_003.phpt?view=markup&rev=1.1
Index: php-src/ext/reflection/tests/closures_003.phpt
+++ php-src/ext/reflection/tests/closures_003.phpt
--TEST--
Reflection on closures: Segfaults with getParameters() and
getDeclaringFunction()
--FILE--
<?php
$closure = function($a, $b = 0) { };
$method = new ReflectionMethod ($closure);
$params = $method->getParameters ();
unset ($method);
$method = $params[0]->getDeclaringFunction ();
unset ($params);
echo $method->getName ()."\n";
$parameter = new ReflectionParameter ($closure, 'b');
$method = $parameter->getDeclaringFunction ();
unset ($parameter);
echo $method->getName ()."\n";
?>
===DONE===
--EXPECTF--
__invoke
__invoke
===DONE===
http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/tests/closures_004.phpt?view=markup&rev=1.1
Index: php-src/ext/reflection/tests/closures_004.phpt
+++ php-src/ext/reflection/tests/closures_004.phpt
--TEST--
Reflection on closures: Segfault with getClosure() on closure itself
--FILE--
<?php
$closure = function() { echo "Invoked!\n"; };
$method = new ReflectionMethod ($closure);
$closure2 = $method->getClosure ($closure);
$closure2 ();
$closure2->__invoke ();
unset ($closure);
$closure2 ();
$closure2->__invoke ();
?>
===DONE===
--EXPECTF--
Invoked!
Invoked!
Invoked!
Invoked!
===DONE===
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php