Re: Package proposal: Net_Ip
| From: | Stefan Walk | Date: | Fri, 30 May 2003 14:45:40 +0000 |
| Subject: | Re: Package proposal: Net_Ip | ||
| References: | 1 2 3 4 5 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-16835@lists.php.net to get a copy of this message | ||
On Fri, May 30, 2003 at 03:30:34PM +0200, cagrET wrote:
> > Answering the question would have taken you just as much time.
>
> u are talking about the class, but u even didnt see it ... nice ...
I did see it. As you might have noticed, I am not the one that you
replied to.
> > You use return statements that will never get executed.
>
> hmm ? show me where ...
You have a construct like if () { return foo; } else { return bar; }
retun baz; there, in the method to get the ip.
>
> > Client-ip and http-x-forwarded-for headers can be set by anyone,
> > and your script would assume that they are the `real ip',
>
> Ok, but there is no other better way to detect Ip through PHP SCRIPT, is
> there ?
> (btw it checks if Http_x_forwarded has Ip format)
> How do u want to detect his Ip ?
In short: You can't. But of all those, REMOTE_ADDR is the only one that
you can 'trust' as it contains the IP of the machine that connected to
you. Anyway, that code doesn't fit in a class that handles IPs - it
belongs to HTTP.
> > You use ereg_* instead of preg_*.
>
> :) ....
> sorry but what will be faster ?
>
> $s = '127.0.0.1, 127.0.0.2, 127.0.0.3';
>
> ereg('^([0-9]{1,3}\.){3,3}[0-9]{1,3}', $s)
> or
> preg_match('^([0-9]{1,3}\.){3,3}[0-9]{1,3}', $s)
>
> ? preg will be faster by 0.00000001 second ?
Your pcre pattern lacks delimiters. And pcre is significantly faster
than ereg. 1 million times executed:
ereg("^([0-9]{1,3}\.){3}[0-9]{1,3}$", "192.168.1.23");
real 0m4.230s
user 0m4.166s
sys 0m0.008s
preg_match("/^(?:\d{1,3}\.){3}\d{1,3}$/", "192.168.1.23");
real 0m1.017s
user 0m1.004s
sys 0m0.004s
> There is one problem with PEAR ...
> U use everywhere :: on classess instead of -> on objects
> What do u gain with this ?
No unneccessary objects polluting the program.
> More bloated code ... and more complex , u have to check if isset($this) etc
> ...
No, you don't. You simply don't access $this in static methods.
> do u really think that using
>
> Net_Ip::get();
>
> is faster than
>
> $ip->get()
I don't think, I know.
> and what if i change class name ? i will have to change a lot of code ...
If you need to change a class name, you have done something wrong.
> Is it so problem to make factory/singleton method to create object or return
> instancee of object ?
> $ip =& Net_ip::factory();
It's simply unneccessary.
--
Regards,
Stefan Walk
<swalk@prp0.prp.physik.tu-darmstadt.de>