Jump to content
Larry Ullman's Book Forums

Recommended Posts

I made a class and used self:: in the constructor so it calls all methods directly.

The problem is that when I tried the example in the book with pets it works perfect,

but while doing something nearly the same, just with a computer class, it doesn't work right.

I tried to override a method in a child class and it simply won't override it.

I used static:: and it works perfect. I read the documentation on php.net but I don't seem to get

the 'why' question. Why does it happen that self:: doesn't work, static:: works in this case?

Why do I have to use late static binding?

Link to comment
Share on other sites

The calling class would be the class used to call the method from. Inside class Dog, self::prop; would equal Dog::prop etc.


It's really hard to understand what you doing here without seeing your code, but my feeling is that your code shouldn't really be static. Static methods doesn't really allow for inheritance. The accepted answer in this Stack Overflow gives you some context:



Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...