ID:               33396
 Comment by:       php at taupehat dot com
 Reported By:      gabriel at helicoid dot net
 Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: Any
 PHP Version:      4.3.11
 New Comment:

Not only is the cause of the error a bit >odd< but the error message
itself is pretty opaque.  Perhaps it could be switched to
T_DOUBLE_COLON?  Yeah, it was a funny joke, but php has kind of reached
beyond its roots now and ought to start to shed that sort of silliness.


Previous Comments:
------------------------------------------------------------------------

[2005-06-19 10:35:28] gabriel at helicoid dot net

<?php
class TestOne {

        var $number;

        function TestOne($somenum)
        {
                $this->number = $somenum;
                TestTwo::testFunc();
        }

}

class TestTwo {

        function testFunc()
        {
                echo "{$this->number}\n";
        }

}

$obj = new TestOne(3);
?>

This kind of functionality can't be replicated using call_user_func as
a workaround.

------------------------------------------------------------------------

[2005-06-19 09:52:27] [EMAIL PROTECTED]

You can use call_user_func() while this is not implemented.

------------------------------------------------------------------------

[2005-06-19 05:42:14] gabriel at helicoid dot net

Description:
------------
I believe there is a flaw in how the scope resolution operator works.

You can use a variable containing the name of the method you want to
call on the right hand side of the operator, which works fine. However,
if you try to have the class name on the left hand side in a variable,
you get a parse error:

Parse error: parse error, unexpected T_PAAMAYIM_NEKUDOTAYIM

I dare say that having the class name in a variable is actually more
useful than having the method name in a variable. You can already have
the class name in a variable if you're using the 'new' keyword, as my
example code shows, so the operation of the scope resolution operator
doesn't seem very consistent with this, which it should be.

A work around would be to actually instantiate an object from the
class, as my example code shows, however I don't think this is a
particularly good solution to this problem. eval()ing a section of code
with the class name as a variable would also work, but again, I don't
think this is a good solution either.

I don't _think_ allowing the scope resolution operator to operate in
this manner would break any existing scripts either, but I may be
wrong.

Reproduce code:
---------------
class TestOne {

        function testMethod($num)
        {
                echo "In testMethod - num is $num\n";
        }

}

$method = 'testMethod';
$class = 'TestOne';

TestOne::$method('3');

//$class::testMethod('3'); // This doesn't work, and I believe it
should.

$obj =& new $class;
$obj->testMethod('4');

Expected result:
----------------
I expect $class::testMethod('3') to really evaluate to
TestOne::testMethod('3')

Actual result:
--------------
Parse error: parse error, unexpected T_PAAMAYIM_NEKUDOTAYIM


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=33396&edit=1

Reply via email to