Is there a way to test a variable for “isForEachable”

binkles

New Member
Using PHP, is there a function/method/way to check if a variable contains something that would be safe to put into a foreach construct? Something like\[code\]//the simple case, would probably never use it this bluntlyfunction foo($things){ if(isForEachable($things)) { foreach($things as $thing) { $thing->doSomething(); } } else { throw new Exception("Can't foreach over variable"); }}\[/code\]If your answer is "setup a handler to catch the PHP error", your efforts are appreciated, but I'm looking for something else.
 
Back
Top