felipe          Tue Jun  3 14:07:15 2008 UTC

  Added files:                 (Branch: PHP_5_3)
    /ZendEngine2/tests  magic_methods_001.phpt magic_methods_002.phpt 
                        magic_methods_003.phpt magic_methods_004.phpt 
                        magic_methods_005.phpt magic_methods_006.phpt 
                        magic_methods_007.phpt magic_methods_008.phpt 
                        magic_methods_009.phpt magic_methods_010.phpt 

  Modified files:              
    /ZendEngine2        zend_compile.c 
    /php-src/tests/classes      __call_005.phpt 
  Log:
  - MFH: Fixed bug #44769 (declaring private magic methods should throw error)
  
  
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.c?r1=1.647.2.27.2.41.2.64&r2=1.647.2.27.2.41.2.65&diff_format=u
Index: ZendEngine2/zend_compile.c
diff -u ZendEngine2/zend_compile.c:1.647.2.27.2.41.2.64 
ZendEngine2/zend_compile.c:1.647.2.27.2.41.2.65
--- ZendEngine2/zend_compile.c:1.647.2.27.2.41.2.64     Mon May 12 09:09:05 2008
+++ ZendEngine2/zend_compile.c  Tue Jun  3 14:07:15 2008
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_compile.c,v 1.647.2.27.2.41.2.64 2008/05/12 09:09:05 dmitry Exp $ 
*/
+/* $Id: zend_compile.c,v 1.647.2.27.2.41.2.65 2008/06/03 14:07:15 felipe Exp $ 
*/
 
 #include <zend_language_parser.h>
 #include "zend.h"
@@ -1203,7 +1203,37 @@
                        fn_flags |= ZEND_ACC_PUBLIC;
                }
 
-               if (!(CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE)) {
+               if (CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE) {
+                       if ((name_len == sizeof(ZEND_CALL_FUNC_NAME)-1) && 
(!memcmp(lcname, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)-1))) {
+                               if (fn_flags & ((ZEND_ACC_PPP_MASK | 
ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
+                                       zend_error(E_COMPILE_ERROR, "The magic 
method __call() must have public visibility and can not be static");
+                               }
+                       } else if ((name_len == 
sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1) && (!memcmp(lcname, 
ZEND_CALLSTATIC_FUNC_NAME, sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1))) {
+                               if ((fn_flags & (ZEND_ACC_PPP_MASK ^ 
ZEND_ACC_PUBLIC)) || (fn_flags & ZEND_ACC_STATIC) == 0) {
+                                       zend_error(E_COMPILE_ERROR, "The magic 
method __callStatic() must have public visibility and be static");
+                               }
+                       } else if ((name_len == sizeof(ZEND_GET_FUNC_NAME)-1) 
&& (!memcmp(lcname, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME)-1))) {
+                               if (fn_flags & ((ZEND_ACC_PPP_MASK | 
ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
+                                       zend_error(E_COMPILE_ERROR, "The magic 
method __get() must have public visibility and can not be static");
+                               }
+                       } else if ((name_len == sizeof(ZEND_SET_FUNC_NAME)-1) 
&& (!memcmp(lcname, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME)-1))) {
+                               if (fn_flags & ((ZEND_ACC_PPP_MASK | 
ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
+                                       zend_error(E_COMPILE_ERROR, "The magic 
method __set() must have public visibility and can not be static");
+                               }
+                       } else if ((name_len == sizeof(ZEND_UNSET_FUNC_NAME)-1) 
&& (!memcmp(lcname, ZEND_UNSET_FUNC_NAME, sizeof(ZEND_UNSET_FUNC_NAME)-1))) {
+                               if (fn_flags & ((ZEND_ACC_PPP_MASK | 
ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
+                                       zend_error(E_COMPILE_ERROR, "The magic 
method __unset() must have public visibility and can not be static");
+                               }
+                       } else if ((name_len == sizeof(ZEND_ISSET_FUNC_NAME)-1) 
&& (!memcmp(lcname, ZEND_ISSET_FUNC_NAME, sizeof(ZEND_ISSET_FUNC_NAME)-1))) {
+                               if (fn_flags & ((ZEND_ACC_PPP_MASK | 
ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
+                                       zend_error(E_COMPILE_ERROR, "The magic 
method __isset() must have public visibility and can not be static");
+                               }
+                       } else if ((name_len == 
sizeof(ZEND_TOSTRING_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_TOSTRING_FUNC_NAME, 
sizeof(ZEND_TOSTRING_FUNC_NAME)-1))) {
+                               if (fn_flags & ((ZEND_ACC_PPP_MASK | 
ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
+                                       zend_error(E_COMPILE_ERROR, "The magic 
method __toString() must have public visibility and can not be static");
+                               }
+                       }
+               } else {
                        char *short_class_name;
                        int short_class_name_length;
                        char *short_class_lcname;
@@ -1235,18 +1265,39 @@
                        } else if ((name_len == sizeof(ZEND_CLONE_FUNC_NAME)-1) 
&& (!memcmp(lcname, ZEND_CLONE_FUNC_NAME, sizeof(ZEND_CLONE_FUNC_NAME)-1))) {
                                CG(active_class_entry)->clone = (zend_function 
*) CG(active_op_array);
                        } else if ((name_len == sizeof(ZEND_CALL_FUNC_NAME)-1) 
&& (!memcmp(lcname, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)-1))) {
+                               if (fn_flags & ((ZEND_ACC_PPP_MASK | 
ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
+                                       zend_error(E_COMPILE_ERROR, "The magic 
method __call() must have public visibility and can not be static");
+                               }
                                CG(active_class_entry)->__call = (zend_function 
*) CG(active_op_array);
                        } else if ((name_len == 
sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1) && (!memcmp(lcname, 
ZEND_CALLSTATIC_FUNC_NAME, sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1))) {
+                               if ((fn_flags & (ZEND_ACC_PPP_MASK ^ 
ZEND_ACC_PUBLIC)) || (fn_flags & ZEND_ACC_STATIC) == 0) {
+                                       zend_error(E_COMPILE_ERROR, "The magic 
method __callStatic() must have public visibility and be static");
+                               }
                                CG(active_class_entry)->__callstatic = 
(zend_function *) CG(active_op_array);
                        } else if ((name_len == sizeof(ZEND_GET_FUNC_NAME)-1) 
&& (!memcmp(lcname, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME)-1))) {
+                               if (fn_flags & ((ZEND_ACC_PPP_MASK | 
ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
+                                       zend_error(E_COMPILE_ERROR, "The magic 
method __get() must have public visibility and can not be static");
+                               }
                                CG(active_class_entry)->__get = (zend_function 
*) CG(active_op_array);
                        } else if ((name_len == sizeof(ZEND_SET_FUNC_NAME)-1) 
&& (!memcmp(lcname, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME)-1))) {
+                               if (fn_flags & ((ZEND_ACC_PPP_MASK | 
ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
+                                       zend_error(E_COMPILE_ERROR, "The magic 
method __set() must have public visibility and can not be static");
+                               }
                                CG(active_class_entry)->__set = (zend_function 
*) CG(active_op_array);
                        } else if ((name_len == sizeof(ZEND_UNSET_FUNC_NAME)-1) 
&& (!memcmp(lcname, ZEND_UNSET_FUNC_NAME, sizeof(ZEND_UNSET_FUNC_NAME)-1))) {
+                               if (fn_flags & ((ZEND_ACC_PPP_MASK | 
ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
+                                       zend_error(E_COMPILE_ERROR, "The magic 
method __unset() must have public visibility and can not be static");
+                               }
                                CG(active_class_entry)->__unset = 
(zend_function *) CG(active_op_array);
                        } else if ((name_len == sizeof(ZEND_ISSET_FUNC_NAME)-1) 
&& (!memcmp(lcname, ZEND_ISSET_FUNC_NAME, sizeof(ZEND_ISSET_FUNC_NAME)-1))) {
+                               if (fn_flags & ((ZEND_ACC_PPP_MASK | 
ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
+                                       zend_error(E_COMPILE_ERROR, "The magic 
method __isset() must have public visibility and can not be static");
+                               }
                                CG(active_class_entry)->__isset = 
(zend_function *) CG(active_op_array);
                        } else if ((name_len == 
sizeof(ZEND_TOSTRING_FUNC_NAME)-1) && (!memcmp(lcname, ZEND_TOSTRING_FUNC_NAME, 
sizeof(ZEND_TOSTRING_FUNC_NAME)-1))) {
+                               if (fn_flags & ((ZEND_ACC_PPP_MASK | 
ZEND_ACC_STATIC) ^ ZEND_ACC_PUBLIC)) {
+                                       zend_error(E_COMPILE_ERROR, "The magic 
method __toString() must have public visibility and can not be static");
+                               }                               
                                CG(active_class_entry)->__tostring = 
(zend_function *) CG(active_op_array);
                        } else if (!(fn_flags & ZEND_ACC_STATIC)) {
                                CG(active_op_array)->fn_flags |= 
ZEND_ACC_ALLOW_STATIC;
http://cvs.php.net/viewvc.cgi/php-src/tests/classes/__call_005.phpt?r1=1.1.4.2&r2=1.1.4.3&diff_format=u
Index: php-src/tests/classes/__call_005.phpt
diff -u php-src/tests/classes/__call_005.phpt:1.1.4.2 
php-src/tests/classes/__call_005.phpt:1.1.4.3
--- php-src/tests/classes/__call_005.phpt:1.1.4.2       Thu Mar  6 11:02:37 2008
+++ php-src/tests/classes/__call_005.phpt       Tue Jun  3 14:07:15 2008
@@ -22,15 +22,4 @@
 $b->test();
 ?>
 --EXPECTF--
-In A::__call(test1, array(1,a))
-object(B)#1 (0) {
-}
-In A::__call(test2, array(1,a))
-object(B)#1 (0) {
-}
-In A::__call(test3, array(1,a))
-object(B)#1 (0) {
-}
-In A::__call(test4, array(1,a))
-object(B)#1 (0) {
-}
\ No newline at end of file
+Fatal error: The magic method __call() must have public visibility and can not 
be static in %s on line %d

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/magic_methods_001.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/magic_methods_001.phpt
+++ ZendEngine2/tests/magic_methods_001.phpt
--TEST--
Testing several magic methods
--FILE--
<?php

class foo {     
        function __unset($a) {
                print "unset\n";
                var_dump($a);
        }
        
        public function __call($a, $b) {
                print "call\n";
                var_dump($a);
        }
        function __clone() {
                print "clone\n";
        }
        static public function __callstatic($a, $b) {
                print "callstatic\n";
        }
        
        public function __tostring() {
                return 'foo';
        }
}


$a = new foo;

$a->sdfdsa();

$a::test();

clone $a;

var_dump((string)$a);

unset($a->a);

?>
--EXPECT--
call
unicode(6) "sdfdsa"
callstatic
clone
unicode(3) "foo"
unset
unicode(1) "a"

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/magic_methods_002.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/magic_methods_002.phpt
+++ ZendEngine2/tests/magic_methods_002.phpt
--TEST--
Testing __unset with private visibility
--FILE--
<?php

class foo {     
        private function __unset($a) {
                print "unset\n";
        }
}

?>
--EXPECTF--
Fatal error: The magic method __unset() must have public visibility and can not 
be static in %s on line %d

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/magic_methods_003.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/magic_methods_003.phpt
+++ ZendEngine2/tests/magic_methods_003.phpt
--TEST--
Testing __unset declaring as static
--FILE--
<?php

class foo {     
        static function __unset($a) {
                print "unset\n";
        }
}

?>
--EXPECTF--
Fatal error: The magic method __unset() must have public visibility and can not 
be static in %s on line %d

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/magic_methods_004.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/magic_methods_004.phpt
+++ ZendEngine2/tests/magic_methods_004.phpt
--TEST--
Testing __unset() with protected visibility
--FILE--
<?php

class foo {     
        protected function __unset($a) {
                print "unset\n";
        }
}

?>
--EXPECTF--
Fatal error: The magic method __unset() must have public visibility and can not 
be static in %s on line %d

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/magic_methods_005.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/magic_methods_005.phpt
+++ ZendEngine2/tests/magic_methods_005.phpt
--TEST--
Testing __call() declaration in interface with wrong modifier
--FILE--
<?php

interface a {
        static function __call($a, $b);
}

?>
--EXPECTF--
Fatal error: The magic method __call() must have public visibility and can not 
be static in %s on line %d

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/magic_methods_006.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/magic_methods_006.phpt
+++ ZendEngine2/tests/magic_methods_006.phpt
--TEST--
Testing __callstatic declaration in interface with missing the 'static' modifier
--FILE--
<?php

interface a {
        function __callstatic($a, $b);
}

?>
--EXPECTF--
Fatal error: The magic method __callStatic() must have public visibility and be 
static in %s on line %d

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/magic_methods_007.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/magic_methods_007.phpt
+++ ZendEngine2/tests/magic_methods_007.phpt
--TEST--
Testing __set() declaration in abstract class with wrong modifier
--FILE--
<?php

abstract class b {
        abstract protected function __set($a);
}

?>
--EXPECTF--
Fatal error: The magic method __set() must have public visibility and can not 
be static in %s on line %d

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/magic_methods_008.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/magic_methods_008.phpt
+++ ZendEngine2/tests/magic_methods_008.phpt
--TEST--
Testing __set implementation with wrong declaration
--FILE--
<?php

abstract class b {
        abstract function __set($a, $b);
}

class a extends b {
        private function __set($a, $b) {
        }
}

?>
--EXPECTF--
Fatal error: The magic method __set() must have public visibility and can not 
be static in %s on line %d

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/magic_methods_009.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/magic_methods_009.phpt
+++ ZendEngine2/tests/magic_methods_009.phpt
--TEST--
Testing __callstatic declaration with wrong modifier
--FILE--
<?php

class a {
        static protected function __callstatic($a, $b) {
        }
}

?>
--EXPECTF--
Fatal error: The magic method __callStatic() must have public visibility and be 
static in %s on line %d

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/magic_methods_010.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/magic_methods_010.phpt
+++ ZendEngine2/tests/magic_methods_010.phpt
--TEST--
Testing __toString() declaration with wrong modifier
--FILE--
<?php

class a {
        static protected function __toString($a, $b) {
        }
}

?>
--EXPECTF--
Fatal error: The magic method __toString() must have public visibility and can 
not be static in %s on line %d

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to