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
Neil
  • 5,919
  • 15
  • 58
  • 85

1 Answers1

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)

Martin Schneider
  • 14,263
  • 7
  • 55
  • 58
  • 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. – Neil Nov 26 '15 at 16:10
  • Isn't grabDataFromJsonResponse doing that? – Naktibalda Nov 27 '15 at 12:26
  • @Naktibalda grabDataFromJsonResponse is not able to take a path when arrays are involved. Any suggestions ? – Neil Nov 27 '15 at 13:32