Weird/strange issue with PHP file
| From: | Jacob Kruger | Date: | Tue, 09 Oct 2012 17:40:47 +0000 |
| Subject: | Weird/strange issue with PHP file | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-30958@lists.php.net to get a copy of this message | ||
Have a main, index.php file that loads another one in using the require() function, and that second
file has a class/object defined in it, with properties, functions, etc., including the following
function definition:
public function setPosition($sPlayer = "red", $iPosition = 3, $iPieceIndex = 0) {
$iIndex = array_flip($this->arPlayers)[$sPlayer];
$this->arPositions[$iIndex][$iPieceIndex] = ($iPosition -1);
}//end of setPosition function
Anyway, issue was that whole main page was just sort of locking up/making server/browser hang/lock
up for roundabout 5 minutes, until browser would generally say something like 500 error, but with no
further details, and this is something that was operating fine on my windows7 64 bit machine,
running under WAMP, but would do this when uploaded files to linux box for actual hosting.
Anyway, sort of assumed it was again maybe something related to some or other strange bit of
character encoding in one of the file's contents, so firstly told notepad++ to make sure both
of the files had their character set encoding set to UTF-8 without BOM, but no go, so then stripped
both files down to literally nothing and started putting the contents back in, piece by piece to try
track down what was causing issue.
Anyway, eventually had whole of index.php back again, until I again told it to require() the second
file, and then issue started again, so there, started off again copying/pasting the second
files's contents back in bit by bit, and got down to the last function, and that was the one
copied in here above - also literally copied and pasted it into this message.
Either way, when it turned out that that re-caused the problem, I then firstly tried stripping
it's contents down line by line, and turned out was the first line causing the issue:
$iIndex = array_flip($this->arPlayers)[$sPlayer];
So, then tried retyping it sort of manually in case there was in fact some or other strange
character in there wasn't seeing, but, nope, so then redid the same operation from that line
into the 2 following lines:
$arFlipped = array_flip($this->arPlayers);
$iIndex = $arFlipped[$sPlayer];
Then left the rest of it as before, and all fine/working now.
Makes me think/wonder that again it must/might have something to do with a sort of hidden character
like at line end, or something, but pretty sure made sure cleaned up whole lines, etc. before trying
to retype, etc., but, either way, really not too sure what could thus cause it to sort of hang up as
if I'd initiated an eternal recursive array iteration, or something, unless it's something
to do with PHP versions, or something, but that doesn't really make much sense if the same
functionality now works split into 2 lines, instead of just operating in one, or something...?
Thoughts, etc.?
Stay well
Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'