Re: object oriented syntax in php

From: Date: Tue, 28 Mar 2006 10:06:30 +0000
Subject: Re: object oriented syntax in php
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-232719@lists.php.net to get a copy of this message
Merlin wrote: <snipped unformatted>
Now I would like to retrieve my needed info out of it. How do I do this? (sounds a bit silly this question, sorry :-) I tried: $ping_result = $ping->ping('php.net'); echo $ping_result["net_ping_result"]["_raw_data"][5]; But this and other tries did not work. My goal is to find out wheter a specified site is reachable.
Next time you want to post data like that please copy and paste the source not the browser output... object(net_ping_result)(11) { ["_icmp_sequence"]=>array(1)
                       {
                           ["61.117):"]=> string(1) "7"
                       }
["_target_ip"]=> string(9) "y2.php.ne" ["_bytes_per_request"]=> string(2) "64" ["_bytes_total"]=> int(192) ["_ttl"]=> string(6) "_seq=2" ["_raw_data"]=>array(7)
                  {
                      [0]=>  string(72) "PING php.net (66.163.161.117) from 192.168.1.114 : 56(84) bytes of data."
                      [1]=>  string(72) "64 bytes from y2.php.net (66.163.161.117): icmp_seq=1 ttl=47 time=211 ms"
                      [2]=>  string(72) "64 bytes from y2.php.net (66.163.161.117): icmp_seq=2 ttl=47 time=206 ms"
                      [3]=>  string(0) ""
                      [4]=>  string(31) "--- php.net ping statistics ---"
                      [5]=> string(55) "2 packets transmitted, 2 received, 0% loss, time 1008ms"
                      [6]=> string(55) "rtt min/avg/max/mdev = 206.299/209.139/211.979/2.840 ms"
                  }
["_sysname"]=> string(5) "linux" ["_round_trip"]=>array(3)
                    {
                       ["min"]=> string(7) "209.139"
                       ["avg"]=>  string(7) "211.979"
                       ["max"]=>  string(5) "2.840"
                    }
["_transmitted"]=> string(1) "2" ["_received"]=> string(1) "2" ["_loss"]=> int(0) } This is the output of a call to var_dump. What you probably want is $ping_result['_raw_data'][5]. However, since the class has nicely extracted the details you may be better off using the _transmitted, _received and _loss members. I'm not familiar with the class in question, but given the names of the member variables I would expect there are accessor methods that you should be using instead of pulling the data out manually. -Stut

« previous php.general (#232719) next »