PWaddict Posted June 9, 2018 Share Posted June 9, 2018 Is there any difference between these? Aren't they doing exactly the same thing? if($page->template == 'admin') return; if($page->template->name == 'admin') return; Link to comment Share on other sites More sharing options...
horst Posted June 9, 2018 Share Posted June 9, 2018 it depends on the context. If OutputFormatting is off, $page->template returns the object, if OutputFormatting is on, it returns only the name. 3 Link to comment Share on other sites More sharing options...
LostKobrakai Posted June 9, 2018 Share Posted June 9, 2018 3 hours ago, horst said: If OutputFormatting is off, $page->template returns the object, if OutputFormatting is on, it returns only the name. Are you sure? I'd expect it to always return the object. It's just that the object implements __toString with it's name, so it's casted to a string if needed. @PWaddict With == it's doing the same thing, because __toString returns the name of the template, but if you'd use === they would no longer have the same result. 4 1 Link to comment Share on other sites More sharing options...
adrian Posted June 9, 2018 Share Posted June 9, 2018 I think this shows it pretty clearly: echo'ing triggers the __toString() method, but dumping returns the object. 1 Link to comment Share on other sites More sharing options...
horst Posted June 10, 2018 Share Posted June 10, 2018 13 hours ago, LostKobrakai said: Are you sure? I'd expect it to always return the object. It's just that the object implements __toString with it's name, so it's casted to a string if needed. Surely you are right. My explanation lacks correctness, as I implied a string conversion, derived from the example pwaddict has given. Thanks for chimimg in and corecct this. ? 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now