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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 10:02:33 2024 UTC