Jump to content

$user comparison odd behaviour


Manaus
 Share

Recommended Posts

Hello,

I have a form submitting some values, but I get a strange behaviour. Just after submitting, I cannot see the delete button. It's visibile when loading the page normally though (GET, !POST).

echo $user." ".$l->createdUser; // always matches
if ($user->isSuperuser() or $user === $l->createdUser) {
	echo "<a href='{$_root}delete-item/?proj=$page->id&item=$l->id'>Delete</a>"; // sometimes visibile, sometimes not	
}

These are my attempts

echo  (int) $user ==  $l->createdUser; // always true, even if values don't match
echo  (int) $user == (int) $l->createdUser; // always true, even if values don't match
echo  (int) $user === (int) $l->createdUser; // always true, even if values don't match
echo  (int) $user->id === (int) $l->createdUser; // never true
echo  $user == $l->createdUser; // usually works correctly, but not just after $user posted something
echo $user === $l->createdUser; // same as previous

Thanks for any suggestion

Link to comment
Share on other sites

Maybe turn on debug mode...

... (int) $user ...

"Notice: Object of class User could not be converted to int"

I'm not sure about the context where you say it doesn't work but these works always

$user === $page->createdUser  (if same object)

$user->id == $page->createdUser->id (if same id)

  • Like 1
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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