# while we're at it (PHP-5.1 & instanceof)

- Thread: https://externals.io/message/16707
- Original archive: https://news-web.php.net/php.internals/16707
- Started by Michael Wallner on 2005-06-15T21:15:46+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #16707 — Michael Wallner — 2005-06-15T21:15:46+00:00

URL: https://externals.io/message/16707#16707

I already complained about that issue several times on IRC
and now that it's time for PHP-5.1 to come, I'll just throw
this question/rant in...

Using `is_a()` throws a notice (E_STRICT IIRC) in PHP5, which
should be fine, because it was deprecated in favour of the
instanceof operator.  But there's quite an ugly problem with
the instnceof operator - it needs the class to be checked
already loaded, while `is_a()` didn't -- *and* instanceof
let the script _die_ if there's no such class.

To replace
	is_a($obj, 'ClassName')
calls one would need to write
	class_exists('ClassName') && ($obj instanceof ClassName)

The point is, that I don't see the point why `is_a()` has been
deprecated (and replaced) by an operator that doesn't provide
the same functionality and can even be harmful (with fatal errors).

Regards,
Mike

---

## #16709 — Andi Gutmans — 2005-06-15T22:07:54+00:00

URL: https://externals.io/message/16707#16709 · In reply to: #16707

Will look into it.

At 11:15 PM 6/15/2005 +0200, Michael Wallner wrote:
>I already complained about that issue several times on IRC
>and now that it's time for PHP-5.1 to come, I'll just throw
>this question/rant in...
>
>Using `is_a()` throws a notice (E_STRICT IIRC) in PHP5, which
>should be fine, because it was deprecated in favour of the
>instanceof operator.  But there's quite an ugly problem with
>the instnceof operator - it needs the class to be checked
>already loaded, while `is_a()` didn't -- *and* instanceof
>let the script _die_ if there's no such class.
>
>To replace
>         is_a($obj, 'ClassName')
>calls one would need to write
>         class_exists('ClassName') && ($obj instanceof ClassName)
>
>The point is, that I don't see the point why `is_a()` has been
>deprecated (and replaced) by an operator that doesn't provide
>the same functionality and can even be harmful (with fatal errors).
>
>Regards,
>Mike

---

## #16713 — Alan Knowles — 2005-06-15T23:36:19+00:00

URL: https://externals.io/message/16707#16713 · In reply to: #16707

http://www.akbkhome.com/blog.php/View/75/removing+that+stupid+is_a
+warning..html

You're not the only one ;)

Regards
Alan

> I already complained about that issue several times on IRC
> and now that it's time for PHP-5.1 to come, I'll just throw
> this question/rant in...
> 
> Using `is_a()` throws a notice (E_STRICT IIRC) in PHP5, which
> should be fine, because it was deprecated in favour of the
> instanceof operator.  But there's quite an ugly problem with
> the instnceof operator - it needs the class to be checked
> already loaded, while `is_a()` didn't -- *and* instanceof
> let the script _die_ if there's no such class.
> 
> To replace
> 	is_a($obj, 'ClassName')
> calls one would need to write
> 	class_exists('ClassName') && ($obj instanceof ClassName)
> 
> The point is, that I don't see the point why `is_a()` has been
> deprecated (and replaced) by an operator that doesn't provide
> the same functionality and can even be harmful (with fatal errors).
> 
> Regards,
> Mike

---

## #16728 — Andi Gutmans — 2005-06-16T13:49:20+00:00

URL: https://externals.io/message/16707#16728 · In reply to: #16707

Seems to work...

At 11:15 PM 6/15/2005 +0200, Michael Wallner wrote:
>I already complained about that issue several times on IRC
>and now that it's time for PHP-5.1 to come, I'll just throw
>this question/rant in...
>
>Using `is_a()` throws a notice (E_STRICT IIRC) in PHP5, which
>should be fine, because it was deprecated in favour of the
>instanceof operator.  But there's quite an ugly problem with
>the instnceof operator - it needs the class to be checked
>already loaded, while `is_a()` didn't -- *and* instanceof
>let the script _die_ if there's no such class.
>
>To replace
>         is_a($obj, 'ClassName')
>calls one would need to write
>         class_exists('ClassName') && ($obj instanceof ClassName)
>
>The point is, that I don't see the point why `is_a()` has been
>deprecated (and replaced) by an operator that doesn't provide
>the same functionality and can even be harmful (with fatal errors).
>
>Regards,
>Mike

---

## #16729 — Michael Wallner — 2005-06-16T14:02:03+00:00

URL: https://externals.io/message/16707#16729 · In reply to: #16728

Hi Andi Gutmans, you wrote:

> Seems to work...

Sorry, what seems to work what way?

Thanks,
--
Michael - < mike(@)php.net

---

## #16744 — Wez Furlong — 2005-06-16T16:56:16+00:00

URL: https://externals.io/message/16707#16744

It seems a bit over-zealous to throw a fatal error when you're writing
code to avoid a fatal error.

If autoload fails, instanceof should simply return false.

--Wez.


> Because it's a generic way of fetching classes and there's no reason to
> change it.
> If there's a real problem then email me.
> 
> Andi
> 
> At 04:55 PM 6/16/2005 +0200, Michael Wallner wrote:
> > […]
