From b7b41a6612f728d88c9fbc572ba02d595cc7479c Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Wed, 6 Feb 2008 20:40:19 +0000 Subject: [PATCH] - MFH Fix missing check and tests --- Zend/zend_API.c | 4 +- .../tests/array/array_map_object1.phpt | 97 +++++++++++++------ 2 files changed, 71 insertions(+), 30 deletions(-) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index db63c01b74..dcf53d3bc2 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -2360,7 +2360,9 @@ static int zend_is_callable_check_func(int check_flags, zval ***zobj_ptr_ptr, ze /* This is a compound name. * Try to fetch class and then find static method. */ zend_class_entry *last_scope = EG(scope); - EG(scope) = ce_org; + if (ce_org) { + EG(scope) = ce_org; + } *ce_ptr = zend_fetch_class(Z_STRVAL_P(callable), clen, ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_SILENT TSRMLS_CC); EG(scope) = last_scope; if (!*ce_ptr) { diff --git a/ext/standard/tests/array/array_map_object1.phpt b/ext/standard/tests/array/array_map_object1.phpt index 33b3b01364..304e1cddf5 100644 --- a/ext/standard/tests/array/array_map_object1.phpt +++ b/ext/standard/tests/array/array_map_object1.phpt @@ -26,7 +26,11 @@ class SimpleClass return $n * $n; } } -var_dump( array_map(array('SimpleClass', 'square'), array(1, 2)) ); +function test($cb, $args) { + echo join('::', $cb) . "\n"; + var_dump(array_map($cb, $args)); +} +test(array('SimpleClass', 'square'), array(1, 2)); echo "\n-- simple class with private variable and method --\n"; class SimpleClassPri @@ -36,7 +40,7 @@ class SimpleClassPri return $var + $n; } } -var_dump( array_map(array('SimpleClassPri', 'add'), array(1)) ); +test(array('SimpleClassPri', 'add'), array(1)); echo "\n-- simple class with protected variable and method --\n"; class SimpleClassPro @@ -46,15 +50,15 @@ class SimpleClassPro return $var1 * $n; } } -var_dump( array_map(array('SimpleClassPro', 'mul'), array(2)) ); +test(array('SimpleClassPro', 'mul'), array(2)); -echo "\n-- class without members --"; +echo "\n-- class without members --\n"; class EmptyClass { } -var_dump( array_map(array('EmptyClass'), array(1, 2)) ); +test(array('EmptyClass'), array(1, 2)); -echo "\n-- abstract class --"; +echo "\n-- abstract class --\n"; abstract class AbstractClass { protected $var2 = 5; @@ -69,9 +73,9 @@ class ChildClass extends AbstractClass echo "defined in child"; } } -var_dump( array_map(array('ChildClass', 'emptyFunction'), array(1, 2)) ); +test(array('ChildClass', 'emptyFunction'), array(1, 2)); -echo "\n-- class with final method --"; +echo "\n-- class with final method --\n"; class FinalClass { private $var4; @@ -79,7 +83,7 @@ class FinalClass echo "This function can't be overloaded"; } } -var_dump( array_map(array('FinalClass', 'finalMethod'), array(1, 2)) ); +test(array('FinalClass', 'finalMethod'), array(1, 2)); echo "\n-- class with static members --\n"; class StaticClass @@ -95,9 +99,9 @@ class StaticClass return array($n); } } -var_dump( array_map(array('StaticClass', 'square'), array(1, 2)) ); -var_dump( array_map(array('StaticClass', 'cube'), array(2)) ); -var_dump( array_map(array('StaticClass', 'retVal'), array(3, 4)) ); +test(array('StaticClass', 'square'), array(1, 2)); +test(array('StaticClass', 'cube'), array(2)); +test(array('StaticClass', 'retVal'), array(3, 4)); echo "-- class implementing an interface --\n"; interface myInterface @@ -113,63 +117,98 @@ class InterClass implements myInterface return 1; } } -var_dump( array_map(array('InterClass', 'square'), array(1, 2))); +test(array('InterClass', 'square'), array(1, 2)); -echo "Done"; ?> +===DONE=== + --EXPECTF-- *** Testing array_map() : object functionality *** -- simple class with public variable and method -- +SimpleClass::square -Strict Standards: array_map() expects parameter 1 to be a valid callback, non-static method SimpleClass::square() should not be called statically in %s on line %d +Strict Standards: array_map() expects parameter 1 to be a valid callback, non-static method SimpleClass::square() should not be called statically in %sarray_map_object1.php on line %d -Warning: array_map() expects parameter 2 to be a valid callback, second array member is not a valid method in %s on line %d -NULL +Strict Standards: Non-static method SimpleClass::square() should not be called statically in %sarray_map_object1.php on line %d + +Strict Standards: Non-static method SimpleClass::square() should not be called statically in %sarray_map_object1.php on line %d +array(2) { + [0]=> + int(1) + [1]=> + int(4) +} -- simple class with private variable and method -- +SimpleClassPri::add -Warning: array_map() expects parameter 1 to be a valid callback, cannot access private method SimpleClassPri::add() in %s on line %d +Warning: array_map() expects parameter 1 to be a valid callback, cannot access private method SimpleClassPri::add() in %sarray_map_object1.php on line %d NULL -- simple class with protected variable and method -- +SimpleClassPro::mul -Warning: array_map() expects parameter 1 to be a valid callback, cannot access protected method SimpleClassPro::mul() in %s on line %d +Warning: array_map() expects parameter 1 to be a valid callback, cannot access protected method SimpleClassPro::mul() in %sarray_map_object1.php on line %d NULL -- class without members -- -Warning: array_map() expects parameter 1 to be a valid callback, array must have exactly two members in %s on line %d +EmptyClass + +Warning: array_map() expects parameter 1 to be a valid callback, array must have exactly two members in %sarray_map_object1.php on line %d NULL -- abstract class -- -Strict Standards: array_map() expects parameter 1 to be a valid callback, non-static method ChildClass::emptyFunction() should not be called statically in %s on line %d +ChildClass::emptyFunction -Warning: array_map() expects parameter 2 to be a valid callback, second array member is not a valid method in %s on line %d -NULL +Strict Standards: array_map() expects parameter 1 to be a valid callback, non-static method ChildClass::emptyFunction() should not be called statically in %sarray_map_object1.php on line %d + +Strict Standards: Non-static method ChildClass::emptyFunction() should not be called statically in %sarray_map_object1.php on line %d +defined in child +Strict Standards: Non-static method ChildClass::emptyFunction() should not be called statically in %sarray_map_object1.php on line %d +defined in childarray(2) { + [0]=> + NULL + [1]=> + NULL +} -- class with final method -- -Strict Standards: array_map() expects parameter 1 to be a valid callback, non-static method FinalClass::finalMethod() should not be called statically in %s on line %d +FinalClass::finalMethod -Warning: array_map() expects parameter 2 to be a valid callback, second array member is not a valid method in %s on line %d -NULL +Strict Standards: array_map() expects parameter 1 to be a valid callback, non-static method FinalClass::finalMethod() should not be called statically in %sarray_map_object1.php on line %d + +Strict Standards: Non-static method FinalClass::finalMethod() should not be called statically in %sarray_map_object1.php on line %d +This function can't be overloaded +Strict Standards: Non-static method FinalClass::finalMethod() should not be called statically in %sarray_map_object1.php on line %d +This function can't be overloadedarray(2) { + [0]=> + NULL + [1]=> + NULL +} -- class with static members -- +StaticClass::square array(2) { [0]=> int(1) [1]=> int(4) } +StaticClass::cube -Warning: array_map() expects parameter 1 to be a valid callback, cannot access private method StaticClass::cube() in %s on line %d +Warning: array_map() expects parameter 1 to be a valid callback, cannot access private method StaticClass::cube() in %sarray_map_object1.php on line %d NULL +StaticClass::retVal -Warning: array_map() expects parameter 1 to be a valid callback, cannot access protected method StaticClass::retVal() in %s on line %d +Warning: array_map() expects parameter 1 to be a valid callback, cannot access protected method StaticClass::retVal() in %sarray_map_object1.php on line %d NULL -- class implementing an interface -- +InterClass::square array(2) { [0]=> int(1) [1]=> int(4) } -Done +===DONE=== -- 2.50.1