FAQ
Is this exepcted behaviour?

➜ ~ cat test.php
<?php
class Foo {
public static function bar() {
print __METHOD__ . "\n";
}
}

$foo = new Foo;
$foo::bar();


➜ ~ php test.php
Foo::bar

I, for one, was surprised that this does what it does with PHP 5.3 and
PHP 5.4 (do not have older version of PHP hand).

--
Sebastian Bergmann Co-Founder and Principal Consultant
http://sebastian-bergmann.de/ http://thePHP.cc/

Search Discussions

  • Stas Malyshev at Aug 10, 2011 at 8:20 pm
    Hi!
    On 8/10/11 1:12 PM, Sebastian Bergmann wrote:
    Is this exepcted behaviour?

    ➜ ~ cat test.php
    <?php
    class Foo {
    public static function bar() {
    print __METHOD__ . "\n";
    }
    }

    $foo = new Foo;
    $foo::bar();


    ➜ ~ php test.php
    Foo::bar

    I, for one, was surprised that this does what it does with PHP 5.3 and
    PHP 5.4 (do not have older version of PHP hand).
    This is how FETCH_CLASS works now - when it has an object in where it
    expects class name, it uses object's class. We could call toString()
    instead but that might be even more surprising.
    --
    Stanislav Malyshev, Software Architect
    SugarCRM: http://www.sugarcrm.com/
    (408)454-6900 ext. 227
  • Etienne Kneuss at Aug 10, 2011 at 10:24 pm
    Hello,
    On Wed, Aug 10, 2011 at 22:20, Stas Malyshev wrote:
    Hi!
    On 8/10/11 1:12 PM, Sebastian Bergmann wrote:

    Is this exepcted behaviour?

    ➜  ~  cat test.php
    <?php
    class Foo {
    public static function bar() {
    print __METHOD__ . "\n";
    }
    }

    $foo = new Foo;
    $foo::bar();


    ➜  ~  php test.php
    Foo::bar

    I, for one, was surprised that this does what it does with PHP 5.3 and
    PHP 5.4 (do not have older version of PHP hand).
    This is how FETCH_CLASS works now - when it has an object in where it
    expects class name, it uses object's class. We could call toString() instead
    but that might be even more surprising.
    Well, FETCH_CLASS has always worked like that, but previously (<5.3)
    variables for class references were only allowed as part of the "new"
    statement,
    e.g. new $obj; The semantic remains the same, only that now variables
    are also allowed for :: calls (since 5.3).
    --
    Stanislav Malyshev, Software Architect
    SugarCRM: http://www.sugarcrm.com/
    (408)454-6900 ext. 227

    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: http://www.php.net/unsub.php


    --
    Etienne Kneuss
    http://www.colder.ch

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedAug 10, '11 at 8:12p
activeAug 10, '11 at 10:24p
posts3
users3
websitephp.net

People

Translate

site design / logo © 2022 Grokbase