Jump to content

Newbie with a pass by reference problem


msknight

Recommended Posts

Hi All,

Sorry for being a complete newbie  ;D

A 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.
Link to comment
Share on other sites

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) params

PHP uses...

your host variable
your port variable
your error number variable
your error message variable
the time out param is taken from the global default time out

2. if you pass (3) params

your host variable
your port variable
error number is not assigned
error message is not assigned
your 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!
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.