]> granicus.if.org Git - php/commitdiff
Fixed bug #47851 (is_callable throws fatal error)
authorDmitry Stogov <dmitry@php.net>
Thu, 2 Apr 2009 09:56:33 +0000 (09:56 +0000)
committerDmitry Stogov <dmitry@php.net>
Thu, 2 Apr 2009 09:56:33 +0000 (09:56 +0000)
NEWS
Zend/zend_API.c
ext/standard/tests/general_functions/bug47857.phpt [new file with mode: 0644]
ext/standard/tests/general_functions/is_callable_basic2.phpt
ext/standard/type.c

diff --git a/NEWS b/NEWS
index 98c2a338a8e4bc6569a3daf451d408f8671b2e01..a40a2759c8ad16e5abc73e922ae24bd4cc05e0da 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ PHP                                                                        NEWS
 - Upgraded bundled sqlite to version 3.6.12. (Scott)
 
 - Fixed bug #47856 (stristr() converts needle to lower-case). (Ilia)
+- Fixed bug #47851 (is_callable throws fatal error). (Dmitry)
 - Fixed bug #47819 (Getting pdo_mysql.so: undefined symbol: mysqlnd_debug_init
   at startup). (Johannes)
 - Fixed bug #47816 (pcntl tests failing on NetBSD). (Matteo)
index 4c81080841b1e06968c0cd9b8d655d2d6d10c54a..b0c460606c5d3c228f9adacf949084475b319eca 100644 (file)
@@ -2540,12 +2540,18 @@ get_function_via_handler:
                                        fcc->object_ptr = EG(This);
                                        if (error) {
                                                zend_spprintf(error, 0, "non-static method %s::%s() %s be called statically, assuming $this from compatible context %s", fcc->calling_scope->name, fcc->function_handler->common.function_name, verb, Z_OBJCE_P(EG(This))->name);
+                                               if (severity == E_ERROR) {
+                                                       retval = 0;
+                                               }
                                        } else if (retval) {
                                                zend_error(severity, "Non-static method %s::%s() %s be called statically, assuming $this from compatible context %s", fcc->calling_scope->name, fcc->function_handler->common.function_name, verb, Z_OBJCE_P(EG(This))->name);
                                        }
                                } else {
                                        if (error) {
                                                zend_spprintf(error, 0, "non-static method %s::%s() %s be called statically", fcc->calling_scope->name, fcc->function_handler->common.function_name, verb);
+                                               if (severity == E_ERROR) {
+                                                       retval = 0;
+                                               }
                                        } else if (retval) {
                                                zend_error(severity, "Non-static method %s::%s() %s be called statically", fcc->calling_scope->name, fcc->function_handler->common.function_name, verb);
                                        }
diff --git a/ext/standard/tests/general_functions/bug47857.phpt b/ext/standard/tests/general_functions/bug47857.phpt
new file mode 100644 (file)
index 0000000..3bdf1c2
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+Bug #47851 (is_callable throws fatal error)
+--FILE--
+<?php
+class foo {
+       function bar() {
+               echo "ok\n";
+       }
+}
+var_dump(is_callable(array('foo','bar')));
+foo::bar();
+var_dump(is_callable(array('Exception','getMessage')));
+Exception::getMessage();
+?>
+--EXPECTF--
+bool(true)
+
+Strict Standards: Non-static method foo::bar() should not be called statically in %sbug47857.php on line %d
+ok
+bool(false)
+
+Fatal error: Non-static method Exception::getMessage() cannot be called statically in %sbug47857.php on line %d
+
index 58443be1fbbd53461faffefc49e948ca9d65e32b..c900032fea5c99cb7a5fea0e4f7614f319188203 100644 (file)
@@ -210,17 +210,11 @@ object_class::func
 bool(false)
 object_class::func
 -- Innerloop iteration 10 of Outerloop iteration 1 --
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 bool(true)
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 bool(true)
 object_class::foo1
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 object_class::foo1
 --- Outerloop iteration 2 ---
@@ -297,17 +291,11 @@ no_member_class::func
 bool(false)
 no_member_class::func
 -- Innerloop iteration 10 of Outerloop iteration 2 --
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 bool(true)
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 bool(true)
 object_class::foo1
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 object_class::foo1
 --- Outerloop iteration 3 ---
@@ -384,17 +372,11 @@ contains_object_class::func
 bool(true)
 contains_object_class::func
 -- Innerloop iteration 10 of Outerloop iteration 3 --
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 bool(true)
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 bool(true)
 object_class::foo1
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 object_class::foo1
 --- Outerloop iteration 4 ---
@@ -471,17 +453,11 @@ contains_object_class::func
 bool(true)
 contains_object_class::func
 -- Innerloop iteration 10 of Outerloop iteration 4 --
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 bool(true)
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 bool(true)
 object_class::foo1
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 object_class::foo1
 --- Outerloop iteration 5 ---
@@ -558,17 +534,11 @@ object_class::func
 bool(false)
 object_class::func
 -- Innerloop iteration 10 of Outerloop iteration 5 --
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 bool(true)
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 bool(true)
 object_class::foo1
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 object_class::foo1
 --- Outerloop iteration 6 ---
@@ -645,17 +615,11 @@ no_member_class::func
 bool(false)
 no_member_class::func
 -- Innerloop iteration 10 of Outerloop iteration 6 --
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 bool(true)
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 bool(true)
 object_class::foo1
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 object_class::foo1
 --- Outerloop iteration 7 ---
@@ -732,17 +696,11 @@ object_class::func
 bool(false)
 object_class::func
 -- Innerloop iteration 10 of Outerloop iteration 7 --
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 bool(true)
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 bool(true)
 object_class::foo1
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 object_class::foo1
 --- Outerloop iteration 8 ---
@@ -819,17 +777,11 @@ Array
 bool(false)
 Array
 -- Innerloop iteration 10 of Outerloop iteration 8 --
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 bool(true)
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 bool(true)
 object_class::foo1
-
-Strict Standards: Non-static method object_class::foo1() should not be called statically in %s on line %d
 bool(true)
 object_class::foo1
 ===DONE===
\ No newline at end of file
index de64b86a76a6f97b55308000c7b5b7fe478b0f5b..a21df63e1b9e057eff8841a813907d6d186a0a9a 100644 (file)
@@ -358,21 +358,29 @@ PHP_FUNCTION(is_callable)
 {
        zval *var, **callable_name = NULL;
        char *name;
+       char *error;
        zend_bool retval;
        zend_bool syntax_only = 0;
+       int check_flags = 0;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|bZ", &var,
                                                          &syntax_only, &callable_name) == FAILURE) {
                return;
        }
-
-       syntax_only = syntax_only ? IS_CALLABLE_CHECK_SYNTAX_ONLY : 0;
+       
+       if (syntax_only) {
+               check_flags |= IS_CALLABLE_CHECK_SYNTAX_ONLY;
+       }
        if (ZEND_NUM_ARGS() > 2) {
-               retval = zend_is_callable(var, syntax_only, &name TSRMLS_CC);
+               retval = zend_is_callable_ex(var, NULL, check_flags, &name, NULL, NULL, &error TSRMLS_CC);
                zval_dtor(*callable_name);
                ZVAL_STRING(*callable_name, name, 0);
        } else {
-               retval = zend_is_callable(var, syntax_only, NULL TSRMLS_CC);
+               retval = zend_is_callable_ex(var, NULL, check_flags, NULL, NULL, NULL, &error TSRMLS_CC);
+       }
+       if (error) {
+               /* ignore errors */
+               efree(error);
        }
 
        RETURN_BOOL(retval);