Knowledgebase

Portal Home > Knowledgebase > Articles Database > Is it just me or is PHP a POS programming language


Is it just me or is PHP a POS programming language




Posted by Phalanxer, 07-17-2012, 10:21 AM
Someone mentioned something that I was pretty sure I observed myself a couple of weeks ago, but I just want to confirm. Then I reload the page, yet I don't see 'yay!', yet the SQL data does indeed equal 0, where as prior it equalled NULL. What the ****!!! Is this for real?? PHP treats a zero as NULL? ... and if so, does someone know how to work around it and if PHP dev's are working to fix this RIDICULOUS design?! Last edited by Phalanxer; 07-17-2012 at 10:32 AM.

Posted by avizzle, 07-17-2012, 10:39 AM
is_numeric()

Posted by Phalanxer, 07-17-2012, 10:47 AM
Thanks. Valid?

Posted by avizzle, 07-17-2012, 11:01 AM
is_numeric returns true or false, you can just do : As far as PHP being a POS, sure the language isn't necessarily the most "elegant" (a word I despise), but with anything the operator is the one who should take the blame for creating poor code. Don't blame the tool if you don't know how to use it.

Posted by Phalanxer, 07-17-2012, 11:12 AM
is_numeric() is no use then because 0 & 1 have different instructions and is_numeric() would run the same instruction for both. The if() tool is clearly crap as it can't distinguish a zero from a null. No, your right. PHP is not crap as a whole. Last edited by Phalanxer; 07-17-2012 at 11:23 AM.

Posted by avizzle, 07-17-2012, 11:24 AM
if...else?

Posted by foobic, 07-17-2012, 09:36 PM
PHP is loosely typed and aims to be "intuitive", so when you use the comparison operator both arguments will be converted to the same type in order to compare them, and in the conversion it's pretty much particular that both zero and null will end up the same. If you want true, type-sensitive comparisons use the === operator instead. (You know the old saying about tools and workmen, right?)

Posted by Matt R, 07-17-2012, 10:34 PM
In that example, $row still wouldn't be updated with a value since you didn't re-query MySQL... PHP is far from a crap language. I've seen your threads today and I can easily state that it's user error in all cases rather than language error. Here's some test code: There's the outcome... It just seems like your values aren't being set. Provide 100% of the code you're using and we can help you, but only providing portions and claiming there are bugs in the PHP engine which operates possibly millions of websites is a bit quick on the trigger...

Posted by foobic, 07-17-2012, 10:50 PM
To be fair Matt, in your code you did miss out this one: It's a bit counter-intuitive that unless you know how PHP does comparisons and the difference between == and ===.

Posted by streaky, 07-18-2012, 12:11 AM
It's not complicated. http://www.blueshoes.org/en/developer/php_cheat_sheet/ Last edited by streaky; 07-18-2012 at 12:25 AM.

Posted by topgun, 07-18-2012, 03:17 AM
The mysql_query returns a resource which is a resultset existing in the memory space of mysql. It is read only. Secondly, understand how type casting works in php. '5' == 5 // true This is because the object on the right of the == operator is automatically cast to the type that is needed for comparison. it is the same as writing. '5' == (sting) 5 // true This saves you a huge amount of time but you can also be caught out if you don't undetand exactly what is going on. Casting varies between php versions and can be OS dependent. Last edited by the_pm; 07-19-2012 at 01:55 PM. Reason: Let's play nice people

Posted by File1eu, 07-18-2012, 10:15 AM
Maybe you want the function: ctype_digit

Posted by FastServ, 07-19-2012, 01:21 PM
If you think PHP is frustrating, don't even try other languages .

Posted by devonblzx, 07-19-2012, 02:16 PM
From the OP: empty() or (!$var) will check for 0 or NULL is_null() will check only for NULL PHP treats 0 as empty which is good for most subjects, you just have to know when to use is_null instead of empty.

Posted by josephgarbett, 07-19-2012, 05:46 PM
If the database column is not a correct field type, you'll get returned null. If 'not null', null, 0 (zero) and empty are treated as the same

Posted by funkywizard, 07-19-2012, 07:54 PM
Your code doesn't make any sense. It's analogous to this: And then saying "well I can double check that $y is 0, so why on earth does it not print 'yay'?". It should be pretty obvious why this isn't working the way you expect it to.

Posted by AI_Guy, 07-20-2012, 03:49 PM
PHP seems pretty consistent to SQL in this respect. This query will always return 0 rows: SELECT * FROM tbl WHERE col = NULL The correct way in SQL is: SELECT * FROM tbl WHERE col IS NULL You should use the is_null(). The notion that anything could equal is sort of an oxymoron. The empty() has no SQL equivalent that I know of, at least in the dialects I use.

Posted by quantumphysics, 07-20-2012, 04:02 PM
the real horror is ever using any mysql_* function



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
Need some help! (Views: 547)


Language:

Contact us