6

Gives an Error:

$this->model::byUserPermission()

Leads to: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM)

Works:

$facade = $this->model;
$facade::byUserPermission()

Is this a PHP Bug? Or can someone explain this to my, why that is happening (I am using php 5.6 and i am new to php. From my point of view, both are exactly the same). Thanks

2
  • Interesting. Maybe :: has a higher precedence than ->, in which case the code will be executed as $this->(model::byUserPermission()), which would be invalid, since calling a method on an undeclared constant doesn't make much sense. Can you try executing ($this->model)::byUserPermission()? I'd think that would evaluate things in the right order. Commented Sep 23, 2015 at 20:12
  • thanks for your help! however thats something I tested before posting and this gives the same error as above... and ($facade)::byUserPermission gives an error too. Commented Sep 23, 2015 at 20:19

1 Answer 1

2

The problem is that this statement $this->model::byUserPermission() is ambiguous. And can be interpreted in multiple ways.

1) You could be trying to use the model property of the class that you are in to call a class's static method. As you are attempting in your question.

2) You could also mean you want to access the property of the class returned by the static function byUserPermission() in the model class.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.