Sunday, April 3, 2011

PHP in_array triggers Internal Server Error

This really shouldn't be this complicated, which suggests I'm doing something wrong, but after checking the docs I can't figure out what.

I'm trying to do a simple check to see if the type of a "tag" is in the list of types to be used during this operation, using this piece of code ($level is passed in as a parameter):

$filter = $this->levels[isset($this->levels[$level])?$level:'max'];
foreach($this->tags as $name => $tag)
{
    $firephp->warn($tag);
    if(in_array($tag->type , $filter) == false) continue;
    // code omitted (this is where it dies)
}

Checking FirePHP reports a 500 Internal Server Error occurred, and I'm 99.9% sure it's here (like I said, that's the line when PHP execution stops). So I suppoes this is two questions: How do I make this work, and why is this happening in the first place?

Also, if it matters, I'm using Apache 2.2.11 on Windows Vista (32-bit) with PHP 5.2.9-1 and MySQL 5.1

UPDATE: Never mind - turned out to be a syntax error. If someone could close this question that would be great.

From stackoverflow
  • Why not turn on error_reporting to get a more detailed error?

    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    
    ehdv : Never mind, I'm an idiot who shot himself in the foot with encapsulation. $tag->type was private, and only accessible via $tag->type(). Making that change fixed it: Many thanks.

0 comments:

Post a Comment