0

After PHP Upgrade I get this Error, on many points:

[Wed Jun 10 22:50:16 2015] [error] [client 10.0.7.85] PHP Fatal error: Cannot use object of type stdClass as array in /var/www/bp/apps/frontend/modules/timekeeping/actions/actions.class.php on line 1275, referer: http://10.0.0.244/timekeeping/overviewAbsent

if (isset($employee_hours[$this->selected_day - 1]->special) && in_array($employee_hours[$this->selected_day - 1]->special, array( 'u', 'm', 's', 'b', 'kk', 'k', 'f', 'fb', 'uf' ))) {
          array_push($this->employees, $employee);
        }
3
  • 3
    Someone could reexplain what the error means, but not answer how it happened. You need to do some debugging. Nobody else can tell what your variables contain, or how it came to be. (Also if multiple code sections look like this, at least refactor it into a function.) Commented Jun 10, 2015 at 20:59
  • What is $employee_hours? Should be an array, but I'm assuming it's an stdClass from your error. You need to show where that is set - since most likely your problem is there. You can convert a stdClass to an array with json_decode($data, true); Commented Jun 10, 2015 at 21:02
  • is it possible $employee_hours[$this->selected_day - 1] is an object? You can use is_object() Commented Jun 10, 2015 at 21:19

1 Answer 1

1

$employee_hours is obviously an object. However, with the $employee_hours[$this->selected_day - 1] notation, you're trying to use it as an associative array – which is invalid.

If the $employee_hours can be of different types (which is not desirable btw), you should at least check that it is an array before using it as one:

if (
    is_array($employee_hours) &&
    isset($employee_hours[$this->selected_day - 1]) &&
    isset($employee_hours[$this->selected_day - 1]->special) &&
    in_array($employee_hours[$this->selected_day - 1]->special, array( 'u', 'm', 's', 'b', 'kk', 'k', 'f', 'fb', 'uf' ))
) {
    // …
}

By the way, you say that this happens since you've upgraded your PHP install. I just made a quick test with various PHP versions, the only version that does not trigger a fatal error is PHP 4.x … all of the PHP 5.x versions produce a fatal error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.