Page 1 of 1

Need use of the php eval function. Re-enable it plz

Posted: 03 March 2022, 20:11
by bidulpik
Hi,
in the backgammon possible moves recursive function I need to use the PHP eval function

Code: Select all

       
       		$txt = '$recursiveMoves';
                for ($i=0; $i < count($newFrom); $i++) {
                    $txt = $txt.'[$newFrom['.$i.']]';
                }
                $txt .= '["detail"] = $moveDetails;';
                eval($txt);
It was available before. Can you re-allow it plz ?

It is really inconvenient to spend time reviewing code that was accepted before.

best regards

Re: Need use of the php eval function. Re-enable it plz

Posted: 04 March 2022, 07:18
by Tisaac
No, eval is the root of evil. You don't need eval at all here (or ever), just use php reference for instance to achieve the same in your case.

Re: Need use of the php eval function. Re-enable it plz

Posted: 06 March 2022, 13:33
by bidulpik
HI,
yes but how can you do that with PHP reference ?
regards

Re: Need use of the php eval function. Re-enable it plz

Posted: 06 March 2022, 14:38
by Tisaac
bidulpik wrote: 06 March 2022, 13:33 HI,
yes but how can you do that with PHP reference ?
regards
Have you read the doc about php ref ?
The code is basically the same, you just need to remove the quote and use & whenevr you access a sub element of an array to make sure it's not implicitely copied by php but rather modifying the original array