]> granicus.if.org Git - php/commitdiff
- MFH Fixed Bug #38064 ignored constructor visibility
authorMarcus Boerger <helly@php.net>
Mon, 7 Aug 2006 23:24:33 +0000 (23:24 +0000)
committerMarcus Boerger <helly@php.net>
Mon, 7 Aug 2006 23:24:33 +0000 (23:24 +0000)
NEWS
Zend/zend_vm_def.h
Zend/zend_vm_execute.h
tests/classes/ctor_visibility.phpt [new file with mode: 0755]

diff --git a/NEWS b/NEWS
index 9464c21bbb423f1d5c8f4e0cfb6e90a9c1a4c2f3..e2e0a7a2cbf8179c8c875968ec8ba06597bc62d8 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -73,6 +73,7 @@ PHP                                                                        NEWS
 - Fixed bug #38168 (Crash in pdo_pgsql on missing bound parameters). (Ilia)
 - Fixed bug #38132 (ReflectionClass::getStaticProperties() retains \0 in key
   names). (Ilia)
+- Fixed bug #38064 (ignored constructor visibility). (Marcus)
 - Fixed bug #38047 ("file" and "line" sometimes not set in backtrace from
   inside error handler). (Dmitry)
 - Fixed bug #37846 (wordwrap() wraps incorrectly). (ddk at krasn dot ru, Tony)
index 64c3084816fef8601a7d0be359462f2e95009c92..57d5dd456767b41b9621dd9720801fd29aad8336 100644 (file)
@@ -1763,6 +1763,9 @@ ZEND_VM_HANDLER(113, ZEND_INIT_STATIC_METHOD_CALL, ANY, CONST|TMP|VAR|UNUSED|CV)
                if(!ce->constructor) {
                        zend_error_noreturn(E_ERROR, "Can not call constructor");
                }
+               if (Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && (ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE)) {
+                       zend_error(E_COMPILE_ERROR, "Cannot call private %s::__constrcut()", ce->name);
+               }
                EX(fbc) = ce->constructor;
        }
 
index ed5b13cc4c6bfcfc6d0049b5a6748aafb1da57cf..111cd42ffa1fafffe85534f3b7efe55e7684de43 100644 (file)
@@ -670,6 +670,9 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_A
                if(!ce->constructor) {
                        zend_error_noreturn(E_ERROR, "Can not call constructor");
                }
+               if (Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE) {
+                       zend_error(E_COMPILE_ERROR, "Cannot call private %s::__constrcut()", ce->name);
+               }
                EX(fbc) = ce->constructor;
        }
 
@@ -871,6 +874,9 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARG
                if(!ce->constructor) {
                        zend_error_noreturn(E_ERROR, "Can not call constructor");
                }
+               if (Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE) {
+                       zend_error(E_COMPILE_ERROR, "Cannot call private %s::__constrcut()", ce->name);
+               }
                EX(fbc) = ce->constructor;
        }
 
@@ -1029,6 +1035,9 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARG
                if(!ce->constructor) {
                        zend_error_noreturn(E_ERROR, "Can not call constructor");
                }
+               if (Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE) {
+                       zend_error(E_COMPILE_ERROR, "Cannot call private %s::__constrcut()", ce->name);
+               }
                EX(fbc) = ce->constructor;
        }
 
@@ -1186,6 +1195,9 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_UNUSED_HANDLER(ZEND_OPCODE_HANDLER_
                if(!ce->constructor) {
                        zend_error_noreturn(E_ERROR, "Can not call constructor");
                }
+               if (Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE) {
+                       zend_error(E_COMPILE_ERROR, "Cannot call private %s::__constrcut()", ce->name);
+               }
                EX(fbc) = ce->constructor;
        }
 
@@ -1276,6 +1288,9 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS
                if(!ce->constructor) {
                        zend_error_noreturn(E_ERROR, "Can not call constructor");
                }
+               if (Z_OBJCE_P(EG(This)) != ce->constructor->common.scope && ce->constructor->common.fn_flags & ZEND_ACC_PRIVATE) {
+                       zend_error(E_COMPILE_ERROR, "Cannot call private %s::__constrcut()", ce->name);
+               }
                EX(fbc) = ce->constructor;
        }
 
diff --git a/tests/classes/ctor_visibility.phpt b/tests/classes/ctor_visibility.phpt
new file mode 100755 (executable)
index 0000000..afc823c
--- /dev/null
@@ -0,0 +1,69 @@
+--TEST--
+ZE2 A private constructor cannot be called
+--FILE--
+<?php
+
+class Test
+{
+    function __construct()
+    {
+        echo __METHOD__ . "()\n";
+    }
+}
+
+class Derived extends Test
+{
+       function __construct()
+       {
+        echo __METHOD__ . "()\n";
+               parent::__construct();
+       }
+       
+       static function f()
+       {
+               new Derived;
+       }
+}
+
+Derived::f();
+
+class TestPriv
+{
+    private function __construct()
+    {
+        echo __METHOD__ . "()\n";
+    }
+
+       static function f()
+       {
+               new TestPriv;
+       }
+}
+
+TestPriv::f();
+
+class DerivedPriv extends TestPriv
+{
+       function __construct()
+       {
+        echo __METHOD__ . "()\n";
+               parent::__construct();
+       }
+       
+       static function f()
+       {
+               new DerivedPriv;
+       }
+}
+
+DerivedPriv::f();
+
+?>
+===DONE===
+--EXPECTF--
+Derived::__construct()
+Test::__construct()
+TestPriv::__construct()
+DerivedPriv::__construct()
+
+Fatal error: Cannot call private TestPriv::__constrcut() in %sctor_visibility.php on line %d