Last active
December 15, 2015 14:19
-
-
Save Paladin/5273393 to your computer and use it in GitHub Desktop.
Not sure how "more code" helps, Joel, but...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$fred = "Joe"; | |
$fred::myName(); // makes a static call to Joe::myname(); | |
class Sam | |
{ | |
public $fred = "Joe"; | |
function whoAreYou() | |
{ | |
$this->fred::myName(); // Erors out with unexpected :: error | |
} | |
} | |
class George | |
{ | |
public $fred = "Joe"; | |
function whoAreYou() | |
{ | |
$fred = $this->fred; | |
$fred::name(); // calls Joe::name() successfully | |
} | |
} | |
Why does George's syntax work but not Sam's? What do I do to Sam's to make it work? |
Yes, but I think I tried ($this->fred)::name() as well. I know I tried it with the {} we use in double-quoted strings, anyway.
I think the trick of treating a variable name as a class name only works on variable names, not on class properties. I don't know any way of doing it without assigning your class property to a variable first. If you figure something out, I'd love to know your solution. I'll noodle on this more tonight too.
It looks so ugly, and seems so inconsistent, but then, this is PHP we're talking about.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think it's how PHP associates the :: operator. It's trying to do $this->(fred::myName()) not ($this->fred)::myName()