php-general Digest 30 Mar 2012 06:23:29 -0000 Issue 7752
php-general Digest 30 Mar 2012 06:23:29 - Issue 7752 Topics (messages 317338 through 317362): Watch out for automatic type casting 317338 by: Arno Kuhl 317342 by: Simon Schick 317344 by: Simon Schick 317345 by: Stuart Dallas 317351 by: tamouse mailing lists Re: DateTime wierdness 317339 by: David OBrien 317340 by: MartÃn Marqués 317341 by: David OBrien 317343 by: David OBrien 317346 by: MartÃn Marqués 317350 by: tamouse mailing lists Re: [PHP-DB] Flow of PHP testClass 317347 by: tamouse mailing lists 317348 by: tamouse mailing lists 317349 by: tamouse mailing lists pcntl_fork behavior with php version 5.1.2 317352 by: Ralf Gnädinger 317353 by: Jim Lucas 317354 by: Stuart Dallas 317355 by: Ralf Gnädinger 317356 by: Ralf Gnädinger Updating Google Plus 317357 by: Brian Dunning 317358 by: Stuart Dallas 317359 by: Brian Dunning 317360 by: Stuart Dallas 317361 by: Brian Dunning PHP 5.4.1 RC1 Released 317362 by: Stas Malyshev Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net -- ---BeginMessage--- I found automatic typecasting can be a bit of a gotcha. $sText = this.is.a.test.text; if ( $pos = strpos($sText, test) !== FALSE) { echo substr($sText, 0, $pos)..substr($sText, $pos, strlen(test))..substr($sText, $pos+strlen(test)); } The code seems logical enough, and the expected result would be: this.is.a.test.text In fact it ends up being: this.is.a.test.text The reason is $pos is typecast as TRUE, not int 10, presumably because it's in the same scope as the boolean test. Then when $pos is later used as an int it's converted from TRUE to 1. You have to bracket the $pos setting to move it into its own scope to prevent it being typecast: if ( ($pos = strpos($sText, test)) !== FALSE) { No doubt it's mentioned somewhere in the php manual, I just never came across it. Just thought I'd highlight one of the gotchas of auto typecasting for any other simpletons like me. Cheers Arno ---End Message--- ---BeginMessage--- Hi, Arno I don't know if this is written somewhere in the php-manual, but I really like this table: http://en.wikipedia.org/wiki/Order_of_operations#Programming_languages I do not really understand why this has some special stuff to do with typecasting ... This is just an order like the operators + and * in math. If you'd ask me, this is exactly what I would expect to happen. Bye Simon 2012/3/29 Arno Kuhl a...@dotcontent.net: I found automatic typecasting can be a bit of a gotcha. $sText = this.is.a.test.text; if ( $pos = strpos($sText, test) !== FALSE) { echo substr($sText, 0, $pos)..substr($sText, $pos, strlen(test))..substr($sText, $pos+strlen(test)); } The code seems logical enough, and the expected result would be: this.is.a.test.text In fact it ends up being: this.is.a.test.text The reason is $pos is typecast as TRUE, not int 10, presumably because it's in the same scope as the boolean test. Then when $pos is later used as an int it's converted from TRUE to 1. You have to bracket the $pos setting to move it into its own scope to prevent it being typecast: if ( ($pos = strpos($sText, test)) !== FALSE) { No doubt it's mentioned somewhere in the php manual, I just never came across it. Just thought I'd highlight one of the gotchas of auto typecasting for any other simpletons like me. Cheers Arno ---End Message--- ---BeginMessage--- Hi, Arno FYI: I found a page in the php-manual that's exactly for that: http://www.php.net/manual/en/language.operators.precedence.php p.s. some of them were also new to me Thanks for getting me to read it. Bye Simon 2012/3/29 Simon Schick simonsimc...@googlemail.com: Hi, Arno I don't know if this is written somewhere in the php-manual, but I really like this table: http://en.wikipedia.org/wiki/Order_of_operations#Programming_languages I do not really understand why this has some special stuff to do with typecasting ... This is just an order like the operators + and * in math. If you'd ask me, this is exactly what I would expect to happen. Bye Simon 2012/3/29 Arno Kuhl a...@dotcontent.net: I found automatic typecasting can be a bit of a gotcha. $sText = this.is.a.test.text; if ( $pos = strpos($sText, test) !== FALSE) { echo substr($sText, 0, $pos)..substr($sText, $pos, strlen(test))..substr($sText, $pos+strlen(test)); } The code seems logical enough, and the expected result would be: this.is.a.test.text In
php-general Digest 30 Mar 2012 21:39:48 -0000 Issue 7753
php-general Digest 30 Mar 2012 21:39:48 - Issue 7753 Topics (messages 317363 through 317380): Re: Watch out for automatic type casting 317363 by: Arno Kuhl 317365 by: Arno Kuhl PHP 5.4.1 RC1 Released 317364 by: Stas Malyshev request for feedback on logAndHandler 317366 by: rene7705 317367 by: marco.behnke.biz 317372 by: rene7705 securing a script that exec()s 317368 by: rene7705 317370 by: Bastien 317371 by: David OBrien 317373 by: Peter Bauer 317374 by: David OBrien 317375 by: rene7705 317377 by: Mike Mackintosh Re: [PHP-DEV] PHP 5.4.1 RC1 Released 317369 by: Nikita Popov Surge 2012 CFP is Open! 317376 by: Katherine Jeschke PHP preg_replace_callback with unicode 317378 by: Jimmy Chen Re: Thinking out loud - a continuation... 317379 by: Robert Cummings Re: Node.PHP 317380 by: Hiyarli Baba Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net -- ---BeginMessage--- -Original Message- From: Simon Schick [mailto:simonsimc...@googlemail.com] Sent: 29 March 2012 07:19 PM To: a...@dotcontent.net Cc: php-gene...@lists.php.net Subject: Re: [PHP] Watch out for automatic type casting Hi, Arno FYI: I found a page in the php-manual that's exactly for that: http://www.php.net/manual/en/language.operators.precedence.php p.s. some of them were also new to me Thanks for getting me to read it. Bye Simon Thanks Simon and others, thought it was typecasting, but precedence makes more sense. I remember seeing that table when I first started using php, which is why I always use AND and OR rather than and || because it's lower precedence than the assignment and the ternary operators, but I couldn't remember where I'd seen it. So thanks for linking to it. Cheers Arno ---End Message--- ---BeginMessage--- -Original Message- From: Simon Schick [mailto:simonsimc...@googlemail.com] Sent: 29 March 2012 07:19 PM To: a...@dotcontent.net Cc: php-gene...@lists.php.net Subject: Re: [PHP] Watch out for automatic type casting Hi, Arno FYI: I found a page in the php-manual that's exactly for that: http://www.php.net/manual/en/language.operators.precedence.php p.s. some of them were also new to me Thanks for getting me to read it. Bye Simon Thanks Simon and others, thought it was typecasting, but precedence makes more sense. I remember seeing that table when I first started using php, which is why I always use AND and OR rather than and || because it's lower precedence than the assignment and the ternary operators, but I couldn't remember where I'd seen it. So thanks for linking to it. Cheers Arno -- BTW interesting to note on that precedence page that ! has a higher precedence than = (which you'd expect it to be) but you can still do if (!$a = foo()) I use that form often (as I'm sure many others do) and just took it for granted that it works even though the order of precedence says it shouldn't. It could be expanded to if ($a = foo() != TRUE) But that wouldn't get the expected result due to order of precedence, though at first glance you could reasonably expect it to work because of if (!$a = foo()) being valid. I think that's why it's so easy to be caught out (at least for me) by the similar form of if ( $pos = strpos($sText, test) !== FALSE) Cheers Arno ---End Message--- ---BeginMessage--- Hi! We would like to announce the first RC of the 5.4.1 version. This is mainly a bugfix release, including all fixes that did not make the cut for 5.4.0 and new issues since then. Please test it and notify us of any problems you may encounter. The full list of the fixes is as always in the NEWS file. You can download the packages from: http://downloads.php.net/stas The Windows team provides windows binaries for the release. As always you find them at: http://windows.php.net/qa/ This is also the first release we are making from our brand new Git setup, please tell us if you notice any glitches. You can read more about the Git migration here: http://www.php.net/archive/2012.php#id2012-03-20-1 We plan the next RC for 5.4.1 in two weeks, on April 12th. Regards, Stas David ---End Message--- ---BeginMessage--- Hi. I've recently got rid of some bugs in an older component of mine called logAndHandler. Basically, logAndHandler will catch errors, warning and notices in PHP code and present them in an attractive interface in the browser. Although it does not work in Internet Explorer, and may never work in that browser, I still find it useful for development purposes. I thought now would be a good time to get some early feedback on what else