php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #79937 I think the function call is not stronger than the static property operator
Submitted: 2020-08-06 10:23 UTC Modified: 2020-08-06 11:43 UTC
From: fy dot kenny at gmail dot com Assigned:
Status: Verified Package: Documentation problem
PHP Version: Irrelevant 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: fy dot kenny at gmail dot com
New email:
PHP Version: OS:

 

 [2020-08-06 10:23 UTC] fy dot kenny at gmail dot com
Description:
------------
---
From manual page: https://php.net/functions.variable-functions
---
When calling static methods, the function call is stronger than the static property operator:

Example #3 Variable method example with static properties

<?php
class Foo
{
    static $variable = 'static property';
    static function Variable()
    {
        echo 'Method Variable called';
    }
}

echo Foo::$variable; // This prints 'static property'. It does need a $variable in this scope.
$variable = "Variable";
Foo::$variable();  // This calls $foo->Variable() reading $variable in this scope.

?>


Test script:
---------------
<?php
class Foo
{
    static $variable = 'static property';
    static function variable()
    {
        echo 'method variable called';
    }
}

$variable = "variable";

echo "<br>" . Foo::$variable; // This prints 'static property'. It does need a $variable in this scope.
// Foo::$variable; == Foo::$variable This is not appended dynamic static variable

echo "<br>" . Foo::$$variable;
// Foo::$$variable; == Foo::$variable This is appended dynamic static variable

echo "<br>" . Foo::$variable();  // This calls $foo->Variable() reading $variable in this scope.
// Foo::$variable(); == Foo::variable()


?>

Expected result:
----------------
static property
static property
method variable called

Actual result:
--------------
static property
static property
method variable called

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-08-06 11:43 UTC] cmb@php.net
-Status: Open +Status: Verified -Operating System: win10 +Operating System: * -PHP Version: 7.4.8 +PHP Version: Irrelevant
 [2020-08-06 11:43 UTC] cmb@php.net
To begin with, I don't think there is any "static property operator".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC