php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #27304 ZE2 Static functions don't function properly
Submitted: 2004-02-18 02:44 UTC Modified: 2005-05-26 14:26 UTC
From: john@php.net Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: < 5.0.3 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
35 - 13 = ?
Subscribe to this entry?

 
 [2004-02-18 02:44 UTC] john@php.net
Description:
------------
Static functions don't behave properly at all. They can be called from an object-context and provide no means to even confirm from within the function if it has been called from a static context or not.

I understand that static methods should never have access to $this regardless of context, but unless the engine enforces a restriction on calling static functions from an object context this behavior is completely counter-intuitive and inconsistent. Not only does the engine not catch this, but the developer cannot either.



Reproduce code:
---------------
<?php
        error_reporting(E_ALL);
        class Staticexample {
                const a = 10;

                static function test() {
                        
                        var_dump(isset($this));

                }

                
        }
       
        $b = new Staticexample();
        Staticexample::test();
        $b->test();
        
?>

Expected result:
----------------
bool(false)
bool(true)


Actual result:
--------------
bool(false)
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-26 14:26 UTC] helly@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Mar 03 07:01:28 2024 UTC