is_a, instanceof, conclusion

php.internals

Pierre-Alain Joye

21 years ago
Hello, As there is no way to find a solution to the two different vision (pedantic, non pedantic ;). I propose to do not deprecate is_a. It cannot hurt neither is_a (is_a uses instanceof too) or instanceof. The only cons for is_a is a little slow down, which is negligeable. Any objection? Regards, --Pierre

Andi Gutmans

21 years ago
I don't mind undeprecating it while I continue to digest the whole instanceof thread and look at real-world examples... At 09:46 AM 8/10/2005 +0200, Pierre-Alain Joye wrote:

Michael Wallner

21 years ago
Hi Andi Gutmans, you wrote:
> I don't mind undeprecating it while I continue to digest the whole > instanceof thread and look at real-world examples...
After all I think there's more hidden behind than just your argument about the generic way...? Why are you defending this broken bridge that hard? You're saying that PHP shouldn't be that dynamic regarding this issue, so why does it try do dynamically load a class within instanceof (which is needless *in every case* anyway)? I think PEAR qualifies as a "real-world" example and there is_a() is used about 680 times, now if that would be instanceof and we assume 10% to check for a non-existing class, it'd bail out at about 70 instances. Regards,
-- Michael - < mike(@)php.net >

Andi Gutmans

21 years ago
At 10:49 AM 8/11/2005 +0200, Michael Wallner wrote:
>Hi Andi Gutmans, you wrote: > > > I don't mind undeprecating it while I continue to digest the whole > > instanceof thread and look at real-world examples... > >After all I think there's more hidden behind than just >your argument about the generic way...? Why are you >defending this broken bridge that hard?
Nothing hidden. I just don't think it's broken. I don't think it'll be terrible to change and I will look into it (actually already have). I do think that people here missed the point though. If your code really requires this functionality then I think there's a problem in most cases. I think for most people in favor it was more a philosophical argument then one backed with massive real world usage... About PEAR, I don't know the code and excuse me if I don't trust your stats :) Andi

Pierre-Alain Joye

21 years ago
Hello, Can we just "undeprecate" is_a and move on? I do not have zend karma (hopefully ;), Andi, can you take care of that? Besides real world usages, the main point is not going to be solved that soon, both sides can live with an unpedantic is_a (and not deprecated) and a pedantic instanceof. Regards, --Pierre

Michael Wallner

21 years ago
Hi Andi Gutmans, you wrote:
> Nothing hidden. I just don't think it's broken. I don't think it'll be > terrible to change and I will look into it (actually already have).
Good news!
> I do think that people here missed the point though. If your code really > requires this functionality then I think there's a problem in most > cases. I think for most people in favor it was more a philosophical > argument then one backed with massive real world usage...
Well, IMO both cases are true.
> About PEAR, I don't know the code and excuse me if I don't trust your > stats :)
Heh :) those are approximately - from a pear/ checkout at 10:30am CEST E:\temp\pear>w:\cyg\bin\find . -name \*.php | wc -l 3590 E:\temp\pear>grep -R "is_a(" . | wc -l 685 Thanks,
-- Michael - < mike(@)php.net >

Andi Gutmans

21 years ago
I think you missed the point. Not all places that use is_a() should need this functionality, and it's questionable if they do... At 06:01 PM 8/11/2005 +0200, Michael Wallner wrote:

Michael Wallner

21 years ago
Hi Andi Gutmans, you wrote:
> I think you missed the point. Not all places that use is_a() should need > this functionality, and it's questionable if they do...
That's why I wrote: "and we assume 10% to check for a non-existing class, it'd bail out at about 70 instances" Regards,
-- Michael - < mike(@)php.net >

Andi Gutmans

21 years ago
Dmitry commited the updated instanceof to HEAD. I suggest to merge it into PHP_5_1 as many want it and it's an extremely low risk patch. If people object, we can put it into 5.1.1. So you see, I am not as stubborn as some assumed :) Andi At 06:13 PM 8/11/2005 +0200, Michael Wallner wrote:

Derick Rethans

21 years ago
On Fri, 19 Aug 2005, Andi Gutmans wrote:
> Dmitry commited the updated instanceof to HEAD. I suggest to merge it into > PHP_5_1 as many want it and it's an extremely low risk patch. > If people object, we can put it into 5.1.1.
I saw he made instanceof NOT use autoload anymore. I'm not sure if that is such a good idea, as I'm wondering whether the following will work: file a.php: <?php interface A { } ?> file b.php: <?php class B implements A { } ?> index.php: <?php function __autoload($name) { require $name. '.php'; } $f = new b(); if ($f instanceof A) { $f->doInterfaceFoo(); } ?> regards, Derick

Marcus Börger

21 years ago
Hello Derick, Saturday, August 20, 2005, 10:54:38 AM, you wrote:
> On Fri, 19 Aug 2005, Andi Gutmans wrote:
>> Dmitry commited the updated instanceof to HEAD. I suggest to merge it into >> PHP_5_1 as many want it and it's an extremely low risk patch. >> If people object, we can put it into 5.1.1.
> I saw he made instanceof NOT use autoload anymore. I'm not sure if that > is such a good idea, as I'm wondering whether the following will work:
> file a.php: > <?php > interface A { > }
?>>
> file b.php: > <?php > class B implements A { > }
?>>
> index.php: > <?php
> function __autoload($name) { > require $name. '.php';
That should read: require strtolower($name) . '.php';
> }
> $f = new b();
That should read new B() :-) anyway the above line autoloads a.php. Class a gets compiled so b.php gets autoloaded, too.
> if ($f instanceof A)
With the above A is already loaded as well as B.
> { > $f->doInterfaceFoo(); > }
?>>
> regards, > Derick
Best regards, Marcus

Marcus Börger

21 years ago
Hello Andi, Saturday, August 20, 2005, 3:31:53 AM, you wrote:
> Dmitry commited the updated instanceof to HEAD. I suggest to merge it into > PHP_5_1 as many want it and it's an extremely low risk patch. > If people object, we can put it into 5.1.1.
> So you see, I am not as stubborn as some assumed :)
You're only hard to convince :-) Best regards, Marcus