Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Zend Developer Zone:
PHP Gotchas!
Apr 24, 2006 @ 17:49:58

The Zend Developer Zone has a new post for those out there struggling with the small stuff. You've got the language down and you're learning the syntax, but there's still a few things that elude your grasp. If this is you, check out their list of "PHP Gotchas" to see if your problem is on there.

Call them obscure, call them pointless, call them "newb mistakes." Whatever you call them, you've more than likely been tripped up at some point in your PHP coding journey by seemingly odd or illogical behaviors of the language. With PHP being a loosely-typed language, funny things are bound to happen.

PHP is an easy language to pick up for the casual coder--things should "just work." But not everyone comes into PHP development with a strong programming background, so here are some charming examples of ways PHP can trip you up if you aren't careful. Put on your thinking caps--here comes the science!

Included in their list of common problems for budding PHP developers are things like finding a "needle" in a string "haystack", working with constants, using and/or, and the __toString functionality in PHP5.

tagged: gotchas strings constants tostring logic math gotchas strings constants tostring logic math

Link:

Zend Developer Zone:
PHP Gotchas!
Apr 24, 2006 @ 17:49:58

The Zend Developer Zone has a new post for those out there struggling with the small stuff. You've got the language down and you're learning the syntax, but there's still a few things that elude your grasp. If this is you, check out their list of "PHP Gotchas" to see if your problem is on there.

Call them obscure, call them pointless, call them "newb mistakes." Whatever you call them, you've more than likely been tripped up at some point in your PHP coding journey by seemingly odd or illogical behaviors of the language. With PHP being a loosely-typed language, funny things are bound to happen.

PHP is an easy language to pick up for the casual coder--things should "just work." But not everyone comes into PHP development with a strong programming background, so here are some charming examples of ways PHP can trip you up if you aren't careful. Put on your thinking caps--here comes the science!

Included in their list of common problems for budding PHP developers are things like finding a "needle" in a string "haystack", working with constants, using and/or, and the __toString functionality in PHP5.

tagged: gotchas strings constants tostring logic math gotchas strings constants tostring logic math

Link:

Professional PHP Blog:
Two preg_replace Escaping Gotchas
Nov 14, 2005 @ 12:14:49

From the Professional PHP Blog today there are two "preg_replace gotchas" they wanted to let you know about.

preg_replace is a major workhorse function in PHP. Unfortunately, there are some less than obvious issues with using it properly. Here are two:

  • The e modifier causes the replacement value of preg_replace (including backreferences) to be evaluated as PHP code. This is a powerful capability. If you've ever seen an SQL injection, this sounds dangerous. It would be, too, but PHP automatically escapes any backreferences because building the string to evaluate.
  • Second, most users of the preg_ functions are familiar with preg_quote for escaping strings to use them as literals in regular expression patterns. However, many people don't realize that the replacement parameter of preg_replace also has special characters.

He also gives code examples of each of these situations and shows you what to do to take the safer route around them...

tagged: preg_replace gotchas problem preg_replace gotchas problem

Link:

Professional PHP Blog:
Two preg_replace Escaping Gotchas
Nov 14, 2005 @ 12:14:49

From the Professional PHP Blog today there are two "preg_replace gotchas" they wanted to let you know about.

preg_replace is a major workhorse function in PHP. Unfortunately, there are some less than obvious issues with using it properly. Here are two:

  • The e modifier causes the replacement value of preg_replace (including backreferences) to be evaluated as PHP code. This is a powerful capability. If you've ever seen an SQL injection, this sounds dangerous. It would be, too, but PHP automatically escapes any backreferences because building the string to evaluate.
  • Second, most users of the preg_ functions are familiar with preg_quote for escaping strings to use them as literals in regular expression patterns. However, many people don't realize that the replacement parameter of preg_replace also has special characters.

He also gives code examples of each of these situations and shows you what to do to take the safer route around them...

tagged: preg_replace gotchas problem preg_replace gotchas problem

Link:


Trending Topics: