Is it intentional that the DOUBLE_COLON operator can be used on a variable that contains a reference to an object?

<?php
class C
{
    public function m()
    {
        print '*';
    }
}

$c = new C;
$c::m();

Until yesterday I thought that only the OBJECT_OPERATOR (->) can be used on a variable that contains an object. https://3v4l.org/59Xap proved me wrong.

As the deprecation / strict standards notices suggest, though, $c::m() does not invoke the method m() on the object referenced by $c. It invokes the method statically on C (the class of the object referenced by $c): https://3v4l.org/19taB

I think that using :: on a variable that contains an object should not "fall back" to a static access on the object's class. Instead the runtime should error out.

What do you think?

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

Reply via email to