Here’s a quick question for the wider PHP programming community … if you’re writing code that tests for the presence of an array, should is_array() also accept objects that behave like arrays?

[code lang=”php”]
$testObject = new ArrayObject(array(‘Tom’));
$testResult = is_array($testObject);
[/code]

On PHP 5.3.2, $testResult gets set to false. If you wanted to get an object that behaves like an array past this sort of test, you’d have to write:

[code lang=”php”]
$testObject = new ArrayObject(array(‘Tom’));
$testResult = (is_array($testObject) || $testObject instanceof ArrayAccess);
[/code]

I’m just curious as to what other PHP programmers think of this. Having to write the second test is longer, and there seems to be little or no benefit gained by having to do so.

What do you think?

Be the first to leave a comment »

We’re Hiring

Posted by Stuart Herbert on July 19th, 2010 in PHP In Business.

I’m looking for a PHP developer to fill a permanent web team lead developer & team leader role, based in Bath in the UK. The role is with Gradwell, a multi-award winning provider of business internet services (we’re also one of the top 50 fastest growing UK tech companies according to Deloitte), reporting directly to me in the Engineering department. We have some exciting projects (including a public-facing API) to deliver and the usual challenges of morphing legacy code to solve.

If you’re interested, drop me a line at the office (stuart.herbert at gradwell dot com) to get more details and explain why you’d be worth an interview 🙂

No agencies, thanks.

Be the first to leave a comment »

This Month

July 2010
M T W T F S S
« Feb   Aug »
 1234
567891011
12131415161718
19202122232425
262728293031