Jump to content

Unexpected behavior with PHP selector with empty string


suntrop
 Share

Recommended Posts

I noticed something strange, with a selector I cannot explain why this happens.

$item_number = ' ';
$p = wire('pages')->get('template=product, item_number=' . $item_number);
echo $p->title;

The code above finds a page with an item_number set to the value of "50032". There is no space (had a look at the DB).

I would have though using the = operator the code above gets nothing or if present something with an empty item_number. But no with a totally different value.

It works as expected if I change the code to:

$p = wire('pages')->get("template=product, item_number='{$item_number}'");

Does anybody know why the first code example works differently?

image.thumb.png.4c0f489c79894757d7b611cf291264be.png

PW 3.0.243

Link to comment
Share on other sites

Both codes are NOT giving the same selector, you could check by printing it.

First case gives: "item_number= " (with a space)
Second one gives: "item_number=' '" (space inside quotes)

To find empty values, you can just use "item_number=''" (no space inside quotes), or "item_number=" (nothing after equal).

But I don't know why the first one is returning a page with item_number=50032. If you're sure everything is right on your side, maybe report a bug on Github.

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

×
×
  • Create New...