Riko Posted July 14, 2019 Share Posted July 14, 2019 Hello, The following code is part of larger script that worked in php 5.3 //Translate string ($str) to UTF-8 from given charset function strToUtf8($str){ $chars = unpack('C*', $str); $cnt = count($chars); for($i=1;$i<=$cnt;$i++) { //echo "Char->" . $chars[$i]; $this->_charToUtf8(&$chars[$i]); //echo " utf8->" . $chars[$i] . "<br>"; } $returnstr = implode("",$chars); //echo "Return after implode() " . $returnstr; return $returnstr; } However: Under php 7.1 i get a syntax error ( syntax error, unexpected '&' in your code ) on this line: $this->_charToUtf8(&$chars[$i]); Can someone suggest changes for the code so it will work under 7.1? Thanks in advance GeeJay Quote Link to comment https://forums.phpfreaks.com/topic/308965-help-with-53-code-to-71-code/ Share on other sites More sharing options...
Barand Posted July 14, 2019 Share Posted July 14, 2019 (edited) You can't pass arguments by reference in the function call. The "by reference" should be defined in the function definition EG // define function function my_func(&$chr) { // do something to $chr ++$chr; } // call function $x = "A"; echo $x; // A my_func($x); echo $x; // B (I am surprised that that 5.3 didn't have an adverse reaction to your code. I thought that restriction had been around longer than that) Edited July 14, 2019 by Barand code revision Quote Link to comment https://forums.phpfreaks.com/topic/308965-help-with-53-code-to-71-code/#findComment-1568378 Share on other sites More sharing options...
requinix Posted July 14, 2019 Share Posted July 14, 2019 26 minutes ago, Barand said: (I am surprised that that 5.3 didn't have an adverse reaction to your code. I thought that restriction had been around longer than that) You're right, it was deprecated in 5.3 and removed in 5.4. OP probably had warnings hidden. Quote Link to comment https://forums.phpfreaks.com/topic/308965-help-with-53-code-to-71-code/#findComment-1568379 Share on other sites More sharing options...
Riko Posted July 14, 2019 Author Share Posted July 14, 2019 Hello, Thank you for your quick answers. I must tell you that I am an absolute noob with php (You probably guessed that already). Could you give an example of what the code would be in 7.1 Greetings Quote Link to comment https://forums.phpfreaks.com/topic/308965-help-with-53-code-to-71-code/#findComment-1568383 Share on other sites More sharing options...
Barand Posted July 14, 2019 Share Posted July 14, 2019 1 hour ago, Riko said: Could you give an example of what the code would be in 7.1 I already have. Quote Link to comment https://forums.phpfreaks.com/topic/308965-help-with-53-code-to-71-code/#findComment-1568388 Share on other sites More sharing options...
cyberRobot Posted July 15, 2019 Share Posted July 15, 2019 On 7/14/2019 at 8:35 AM, Riko said: Could you give an example of what the code would be in 7.1 Also note that the link provided by requinix contains examples of passing by reference. In case you're not aware, PHP can be set to display all errors and warnings. The settings are helpful during the development / debugging process. Just be sure to change the settings back to where errors / warnings are not displayed publicly once your script is live. The messages aren't user friendly and can aid malicious actors. More information about showing / hiding errors and warnings can be found here:https://www.php.net/manual/en/function.error-reporting.php Quote Link to comment https://forums.phpfreaks.com/topic/308965-help-with-53-code-to-71-code/#findComment-1568402 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.