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
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: 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

Add a Patch

Pull Requests

Add a Pull Request

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-2020 The PHP Group
All rights reserved.
Last updated: Wed Sep 30 05:01:23 2020 UTC