Notes on Java, Solaris, PHP, LDAP…

December 11, 2007

C-like shortcuts leading to errors in PHP

Filed under: Uncategorized — negev @ 6:06 pm
Tags:

Today I’ve come across yet another tricky error in PHP… I had the following code. $info in it is an LDAP result array. I wanted to extend the if(..) condition to check whether $info[‘count’] is exactly 1. So I took

  if( $info=$myObject->All($res) ) {
}

and changed it into

  if( $info=$myObject->All($res) && $info['count']==1 ) {
}

Suddenly it stopped working, even for the LDAP results about which I knew they had exactly one item. As usual, it was the programmer’s error – but supported by PHP as it doesn’t check types in compile time. What I should have done was

  if( ( $info=$myObject->All($res) ) && $info['count']==1 ) {
}

Yet another reason to use strong-typed languages like Java, rather than script lingos as PHP.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: