[PHP] Re: Object members dynamic access?

2001-08-15 Thread Cerel

Try this :

class foo {
var $var1="hello";
var $var2="world";
}
...
...
$fooinstance = new foo;
$vartest=$fooinstance->var1;
echo ($vartest); // should be 'hello'

This should work, but i had no time to test this code.

See you later

Sean C. McCarthy <[EMAIL PROTECTED]> a écrit dans le message :
[EMAIL PROTECTED]
> Hi All,
>
> I was wondering if it is possible to access dinamically to the members
> of a class. I mean to access like:
>
> --
> class foo {
> var $bar;
> var $barbar;
> }
>
> ..
> ..
>
> $foo_instance = new foo;
> $somevar = $foo->$anothervar;
> -
>
> I now this doesn't work, and have searched the manual and haven't found
> anything on it. I doubt it since this is more or less the work of the
> Arrays and not the way a class should behave. Anyway any ideas? thanks
> in advance.
>
> Sean C. McCarthy
> SCI, S.L. (www.sci-spain.com)



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Problem with a socket in non-blockant state

2001-08-15 Thread Cerel

Ok here is the story :
I got a php script that comunicates with a game server (Half-life). This
script uses socket_set_timeout.
But the build of php i downloaded doesn't support socket_set_timeout().
So i started to modify the script to do without.
Here is the prob : the script use the socket as blockant. But without
socket_set_timeout it could be a problem.So i try with a non-blockant socket
but i don't get any response from the game server.
Here is a portion of the code :

  if (!$cssocket=fsockopen("udp://".$serveraddress,$portnumber,$errnr)) {
   $this->errmsg="No connection";
   return "";
  }

  socket_set_blocking($cssocket,false);
  fwrite($cssocket,$command,strlen($command));

//  sleep(1);
  do {
   $data=fread($cssocket,1024);
   $serverdata.=$data;
   $serverdatalen=strlen($serverdata);
   $socketstatus=socket_get_status($cssocket);
//  } while ($socketstatus["unread_bytes"] );
  } while (time()-$starttime<5 );

The main prob is that : in blockant mode it works fine. In non-blockant mode
i don't receive anything. But if i do a sleep(1) before the first read (the
commented line) then it works..

Another way of the problem :
loop {
readdata from socket;
append to data akready read;
} while moredata or not_timed_out

In blockant mode it works.
In non-blockant mode i never receive something !! WHY ??

I understand why it works in blockant mode : the read function waits untill
the has arrived.
But in non-blockant the read function should return the data already arrived
then return.
And the second time i launch it, it should give me the data that arrived
since the last time.

I think i missed something, but i cannot see what.

Please help me.

Sorry about my English, it's not my main language... :)

See you later





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]