0

I am on PHP53 so codeception 1.8

$response = (array)$I->grabDataFromJsonResponse("result");
\Codeception\Util\Debug::debug($response);

  Array
  (
      [*position] => 0
      [*val] => Array
          (
              [key1] => 10
              [key2] => 1
          )

      [*assocArray] => 1
  )

Now when I try to access the values in the array it gives me error

\Codeception\Util\Debug::debug($response['key1']);

[ErrorException] Undefined index: key1
4
  • as it should be. try \Codeception\Util\Debug::debug($response['*val']['key1']); Commented Nov 26, 2015 at 10:50
  • @Calimero I have tried that , says "Undefined index: *val" How can the values be fetched ? Commented Nov 26, 2015 at 10:51
  • $response[0]['*val']['key1'] Commented Nov 26, 2015 at 11:17
  • @MA-Maddin Notice: Undefined offset: 0 Commented Nov 26, 2015 at 11:20

1 Answer 1

1

This is because of the Object -> array conversion

To access the protected properties (prepended with *) you have to include the sourrounding null bytes:

$response["\0*\0val"]['key1']

(note the double quotes)

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

3 Comments

This works! However I am also looking for an answer where I can directly get hold of an array from the response using codeception BDD style API.
Isn't grabDataFromJsonResponse doing that?
@Naktibalda grabDataFromJsonResponse is not able to take a path when arrays are involved. Any suggestions ?

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.