msknight Posted October 6, 2006 Share Posted October 6, 2006 Hi All,Sorry for being a complete newbie ;DA nice simple one for you. I dabble in different languages, and am working on a PHP project to help people running L2J servers to administer the game. My work is free to the community.I'm having a problem, however, with code that is passing two variables by reference. I understand what I am doing, and I understand the error, which is that passing variables by reference is depreciated in the later versions of PHP. I just don't know enough to be confident of my solution.Although setting the variable in the php.ini file will get around it, and I do set a temporary session variable, this isn't an ideal solution. Also, although fumbling around in the dark is my prefered way of learning, when other people are using my code I sort of owe it to them to say, "I need help!" and then go get it ... hence I'm here.[code]$usetelnet = fsockopen($telnet_host, $telnet_port, &$errno, &$errstr, $telnet_timeout);[/code]This is what I'm doing wrong ... $errno and $errstr are being passed by reference, but if I don't pass them by reference I'm sort of stuffed.To my amateure mind, the other side is probably working on the reference and if I don't pass the right numbers, then it may well write in to an unknown place in memory. That is why I'm concerned.If I do something like ...[code]$errnoref = &$errno;$errstrref = &$errstr;$usetelnet = fsockopen($telnet_host, $telnet_port, $errnoref, $errstrref, $telnet_timeout);[/code]... will that solve my problem; or will I just crash someones server!Any help gratefully appreciated. Quote Link to comment Share on other sites More sharing options...
printf Posted October 6, 2006 Share Posted October 6, 2006 What is your added reference for? PHP by default passes $errno and $errstr by reference, so you don't need to do what your doing and you can name them what ever you want...[code]fsockopen($telnet_host, $telnet_port, $dumb_error, $dumb_message, $telnet_timeout);[/code]quick facts fsockopen!1. if you pass (4) paramsPHP uses...your host variableyour port variableyour error number variableyour error message variablethe time out param is taken from the global default time out2. if you pass (3) paramsyour host variableyour port variableerror number is not assignederror message is not assignedyour time out variable (ie: on windows running the PHP ISAPI filter, timeout can never be set at runtime, it's always taken from the PHP.INI)me! Quote Link to comment Share on other sites More sharing options...
msknight Posted October 6, 2006 Author Share Posted October 6, 2006 Thanks very much for the help.I was right at the begining of my PHP project when I needed to talk with the gameserver via telnet, so I had to copy someone elses telnet code and adjust it. The last two months has seen me learn a lot about PHP, but still not enough to get to this kind of detail yet. Quote Link to comment Share on other sites More sharing options...
printf Posted October 6, 2006 Share Posted October 6, 2006 I posted a few facts so you understand PHP(s) way of handling [b]params[/b] for this function! The manual function definition can sometimes be misleading, but if you read through the facts and some of the user comments it will help you find out things that the developers don't always include!me! Quote Link to comment 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.