# Static method call syntax on objects

- Thread: https://externals.io/message/54497
- Original archive: https://news-web.php.net/php.internals/54497
- Started by Sebastian Bergmann on 2011-08-10T20:12:41+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #54497 — Sebastian Bergmann — 2011-08-10T20:12:41+00:00

URL: https://externals.io/message/54497#54497

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/

---

## #54499 — Stas Malyshev — 2011-08-10T20:20:43+00:00

URL: https://externals.io/message/54497#54499 · In reply to: #54497

Hi!


>    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

---

## #54500 — Etienne Kneuss — 2011-08-10T22:24:01+00:00

URL: https://externals.io/message/54497#54500 · In reply to: #54499

Hello,


> Hi!
>
> 
> > […]
>
> 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
>
> --
> 
> 
>
>



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