# Object[] type hint

- Thread: https://externals.io/message/27789
- Original archive: https://news-web.php.net/php.internals/27789
- Started by Sebastian Bergmann on 2007-02-05T05:57:14+00:00
- Messages: 4
- 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

---

## #27789 — Sebastian Bergmann — 2007-02-05T05:57:14+00:00

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

Hi,

 any chance for the following type hint syntax

   class Example
   {
       public function doSomething(Object[] $objects)
       {
       }
   }

 instead of having to write

   class Example
   {
       public function doSomething(Array $objects)
       {
           foreach ($objects as $object) {
               if (!$object instanceof Object) {
                   throw new InvalidArgumentException;
               }
           }
       }
   }

 Thanks,
Sebastian

-- 
Sebastian Bergmann                      http://www.sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69

---

## #27811 — Stanislav Malyshev — 2007-02-05T17:48:57+00:00

URL: https://externals.io/message/27789#27811 · In reply to: #27789

>    class Example
>    {
>        public function doSomething(Object[] $objects)

And how this would be verified - each time by passing whole array and 
checking each element is an object? I don't think it's a good idea. 
Also, PHP doesn't have [] as array definition (at least not until Andi's 
idea is accepted), only as array resolution, so this syntax is also 
illogical, moreover, it gives you and idea that you could define types 
using [], which you can not.

-- 
Stanislav Malyshev, Zend Products Engineer
stas@zend.com  http://www.zend.com/

---

## #27820 — Sebastian Bergmann — 2007-02-05T18:36:41+00:00

URL: https://externals.io/message/27789#27820 · In reply to: #27811

Stanislav Malyshev wrote:
> And how this would be verified - each time by passing whole array and
> checking each element is an object? I don't think it's a good idea.

 The check would only be performed in the case where one uses the new
 type hint. And if someone needs this, he would manually do the same in
 userspace anyways (see the example in my original mail).

-- 
Sebastian Bergmann                          http://sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69

---

## #27821 — Stanislav Malyshev — 2007-02-05T18:48:15+00:00

URL: https://externals.io/message/27789#27821 · In reply to: #27820

>  The check would only be performed in the case where one uses the new
>  type hint. And if someone needs this, he would manually do the same in
>  userspace anyways (see the example in my original mail).

I would say (IMHO of course) this belongs to userspace. No reason to 
build such a complex and rarely used functionality into the language syntax.
-- 
Stanislav Malyshev, Zend Products Engineer
stas@zend.com  http://www.zend.com/
