flaw in php ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Re: flaw in php ?

Post by kaisellgren »

So do you want 0 to match 'zero' or do you want '0' to match 'zero' ? Or do you not want them to match at all?
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: flaw in php ?

Post by php_east »

@kai. who are you asking ?
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Re: flaw in php ?

Post by kaisellgren »

php_east wrote:@kai. who are you asking ?
You.
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: flaw in php ?

Post by php_east »

well then i think you got the wrong number mate, it's Mark's code, not mine. i'm the one who showed him the flaw. he is the flawee :). but he says he is ok with it, so ask him if you want.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: flaw in php ?

Post by Mark Baker »

The problem I had was that in_array defaults to loose type checking, so that numeric 0 was returning true with the in_array(), and acting out Case 1, when I actually needed it to fall into the Case 2 logic. Fortunately, in_array() accepts the optional third parameter to use strict checking, which gives me the correct result.
But it took me a lot of furtling around to identify that the in_array() test was the cause of my problem - writing a lexical parser isn't the easiest of tasks for debugging given the number of possible permutations of mathematical formulae - and even that it only gave incorrect results when my formulae included a function that takes no arguments (the 0 in question being the number of arguments).
Post Reply