php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39664 Invokation of non-static method as static issue
Submitted: 2006-11-28 19:03 UTC Modified: 2006-11-28 22:33 UTC
From: john dot hargrove at sellingsource dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.0 OS: Gentoo Linux 2.6 kernel
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: john dot hargrove at sellingsource dot com
New email:
PHP Version: OS:

 

 [2006-11-28 19:03 UTC] john dot hargrove at sellingsource dot com
Description:
------------
PHP5 allows you to invoke a non-static method as static if you have E_STRICT disabled through the Class::Method() syntax which is intended functionality.  I believe this bug may actually be a throwback to PHP4 functionality, but it results in funky error reporting in PHP5.  If you make a static call to a non-static method, from an instance of another class, the $this variable is in scope from the calling instance.  This breaks visibility and scope rules.  Note that I saw all the PHP4 bug reports for this marked as bogus for reasons that made sense, but did not see a PHP5 bug marked similarly.  The only reason I can see for this is compatibility?

Also of note is that the method is aware of being out of the context of an object if called from the global scope.  This only occurs from the context of an object (which makes sense).



Reproduce code:
---------------
<?php
        class A
        {
                private $private_var;

                public function Tester()
                {
                        echo $this->private_var;
                }
        }
        class B
        {
                public function TesterBlah()
                {
                        A::Tester();
                }
        }

        $b = new B();
        $b->TesterBlah();
?>


Expected result:
----------------
Fatal error: Using $this when not in object context in /root/bug/test.php on line 8

Actual result:
--------------
Notice: Undefined property:  B::$private_var in /root/bug/test.php on line 8


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-28 19:13 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2006-11-28 22:23 UTC] john dot hargrove at sellingsource dot com
Given that this has been around since PHP4, and the manual not being especially clear about it, and there not really having been a clear answer as to why this is considered intended functionality.  Is it right to say that this is a side effect of static method calls being resolved at compile time, and not necessarily so much intended as it is a very difficult to fix side effect?  I'm not trying to stir the pot, I just want to make sure we're on the same page as far as this being Bogus, as well as anyone else who reads this bug report.
 [2006-11-28 22:33 UTC] tony2001@php.net
Yes, it's some kind of a left-over of PHP4, but it is necessary to keep BC with the code written with PHP4 in mind.
I guess we can/will change it in PHP6, but in 5.x it should remain as it is.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 17:01:33 2025 UTC