php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26924 private methods can be called within a static method
Submitted: 2004-01-15 13:27 UTC Modified: 2004-01-16 07:50 UTC
From: mike@php.net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5CVS-2004-01-15 (dev) OS: *
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: mike@php.net
New email:
PHP Version: OS:

 

 [2004-01-15 13:27 UTC] mike@php.net
Description:
------------
Private class methods can be called by instantiating an object of this class in an static method.

Reproduce code:
---------------
<?php
class t {
    private function dont() {
        echo "intended?\n";
    }
    static function main() {
        $t = new t();
        $t->dont();
    }
}
t::main();
?>


Expected result:
----------------
Fatal error: Call to private method t::dont() ...

Actual result:
--------------
intended?


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-16 06:28 UTC] sniper@php.net
It's all about context..:)
Of course you can call private functions within the class they 
belong to. But you can't call the function from 'outside'.
ie. if you tried to call 't::dont();' you'd get that error..

(or maybe I misunderstood this? :)

 [2004-01-16 07:50 UTC] mike@php.net
Ah, context - you're right... :)

I was just really suprised that I may access a private method of an object by instantiating it and calling obj->meth()

Just tested it with C# - same there :)

However, thanks for clearifying this.

Mike
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Dec 05 15:00:01 2025 UTC