Jump to content

Recommended Posts

Posted

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;

 

Posted

it depends on the context. If OutputFormatting is off, $page->template returns the object, if OutputFormatting is on, it returns only the name.

  • Like 3
Posted
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.

  • Like 4
  • Thanks 1
Posted

I think this shows it pretty clearly:

image.png.13c49916ed76bfa9c0f49bfa285b7cff.png

echo'ing triggers the __toString() method, but dumping returns the object.

  • Like 1
Posted
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. ?

  • Like 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...