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
 [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: Sat Dec 21 14:01:32 2024 UTC