0

I'm getting a Notice and a Warning here, not an error. My code still works. Just wanted to see if someone could figure out why I'm getting the notice and warning.

Notice: Trying to get property of non-object in file.php on line 152

Warning: in_array() expects parameter 2 to be array, null given file.php on line 152

Line 152 is an if() statement:

if($user->type == 'x' && in_array($user->email, $campaign->settings->email_list))
{ do stuff }

I've pinpointed the issue to the $campaign object. Using print_r on $campaign outputs quite a bit of info, but this is the important part:

Campaign Object
{
    [settings] => stdClass Object
        (
            [email_list] => Array
                (
                    [0] => support@domain.com
                    [1] => customer@domain.com
                )
        )
}

Obviously, $campaign->settings->email_list is an array. Why am I getting the Notice and Warning, then? $campaign is created directly above Line 152.

2 Answers2

0

I think you may get this notice because of possible uninitialization (maybe null value) assigned to $campaign->settings campaign's internal object. Please ensure with a var_dump($campaign->settings) what is the real value of the property before the line with in_array function.

  • Should have included that in my original post, but I already did that. `var_dump($campaign->settings)` outputs `object(stdClass)#14 (7) { ["email_list"]=> array(2) { [0]=> string(19) "support@domain.com" [1]=> string(19) "customer@domain.com" }" } –  Jan 10 '15 at 05:51
  • Sorry, you wrote you used print_r. Nevertheless the *Notice: Trying to get property of non-object in file.php on line 152* points in that direction. This is strange :) –  Jan 10 '15 at 06:04
0

try this some time it will works.

$campaign['settings']['email_list']
ABIRAMAN
  • 929
  • 8
  • 12
  • Thanks for trying to help! That would only work if `$campaign` was an Array, and its `settings` element was an Array. Since I'm dealing with objects, this particular solution doesn't apply. –  Jan 10 '15 at 05:53
  • 1
    http://stackoverflow.com/questions/2476876/how-do-i-convert-an-object-to-an-array check this link you will get an idea – ABIRAMAN Jan 10 '15 at 06:04