0

I have this little snippet:

$action = $_GET['action'];
// some other code

// works
$properties = $client->__soapCall($action, array(
    array(
        'Page' => $x
    )
));

// try to get access to values by var $action
$obj = $properties->$action->item;

This gives me an error. My intention was to use the script only once for multiple operations by getting different actions.

...but I have no idea how to solve this and I haven't found any helpful posts or articles.

var_dump($properties):

object(stdClass)#84 (4) {
    ["PropertyGroups"]=>
        object(stdClass)#85 (1) {
            ["item"]=>
                array(73) {
                    [0]=>
                        object(stdClass)#86 (7) {
                            ["PropertyGroupID"]=>int(1)
                        }
                }
          }
  }
5
  • This gives me an error. We should guess it right? Commented Jan 14, 2016 at 9:29
  • No, you shouldn't. Sorry. If action = GetPropertyGroups, Undefined property: stdClass::$GetPropertyGroups Commented Jan 14, 2016 at 9:31
  • var_dump($properties) Commented Jan 14, 2016 at 10:15
  • What PHP version are you using? Commented Jan 14, 2016 at 10:27
  • I am currently using PHP 5.5.30 but it's possible to upgrade to 7.0.1 Commented Jan 14, 2016 at 10:31

1 Answer 1

1

The script and this line

$obj = $properties->$action->item;

Are absolutely OK. But, as you pointed out in the comments,

If action = GetPropertyGroups, Undefined property: stdClass::$GetPropertyGroups

You have PropertyGroups property in $properties, not GetPropertyGroups.

You should check if the property you're looking for exists:

property_exists($properties, $action)
Sign up to request clarification or add additional context in comments.

1 Comment

You are absolutly right. This was my mistake, I didn's see it. Thank you!

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.