On the game php side my state uses an argument function to pass valid locations to play like the reversi tutorial.
I build the locations in php scetched like this
$objData = self::getObjectListFromDB(...)
$objArr = array();
foreach ($objData as $idx => $Data)
{
...do some calcs and filter entries to valid ones...
$objArr[] = array('key1'=>$val1, 'key2'=>$val2,....)
}
$objArr is an array of arrays with indices/keys of 0,1,2,... that is returned from the argument function.
Then, this argument function is named as the "args" function in the state file, so this array shows up on the java side as part of onEnteringState.
Most of the time this works, I see objArr and it has the correct contents and important for my checks in onEnteringState , I can get the length of objArr from args.objArr.length.
However, on the php side I have another filtering step where I remove array elements from $objArr using the php unset() function. This again works most of the time on the js side and I get the correct length from args.objArr.length.
However, there is catch, if on the php side I use unset() on the first element of $objArr (e.g., unset($objArr[0])), then on the js side args.objArr.length becomes 'undefined'
even if there are plenty of elements left in $objArr. This has caused some deal of hunting down this oddity since unset() in php does not reindex the entries after removing one. I am guessing that something is not quite correct in the hand off between php and js for this scenario.
Summary: avoid unset() for arrays generated in the argument function on the php side handed over to javascript. The length property of the array can become undefined in onEnteringState when you don't expect it to.
I build the locations in php scetched like this
$objData = self::getObjectListFromDB(...)
$objArr = array();
foreach ($objData as $idx => $Data)
{
...do some calcs and filter entries to valid ones...
$objArr[] = array('key1'=>$val1, 'key2'=>$val2,....)
}
$objArr is an array of arrays with indices/keys of 0,1,2,... that is returned from the argument function.
Then, this argument function is named as the "args" function in the state file, so this array shows up on the java side as part of onEnteringState.
Most of the time this works, I see objArr and it has the correct contents and important for my checks in onEnteringState , I can get the length of objArr from args.objArr.length.
However, on the php side I have another filtering step where I remove array elements from $objArr using the php unset() function. This again works most of the time on the js side and I get the correct length from args.objArr.length.
However, there is catch, if on the php side I use unset() on the first element of $objArr (e.g., unset($objArr[0])), then on the js side args.objArr.length becomes 'undefined'
Summary: avoid unset() for arrays generated in the argument function on the php side handed over to javascript. The length property of the array can become undefined in onEnteringState when you don't expect it to.