# Type hinting

- Thread: https://externals.io/message/48820
- Original archive: https://news-web.php.net/php.internals/48820
- Started by Christian Kaps on 2010-06-17T18:36:55+00:00
- Messages: 8
- 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

---

## #48820 — Christian Kaps — 2010-06-17T18:36:55+00:00

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

Hi,

I know the discussion is about scalar type hints. But what is with a
object type hint as base for all objects?

What is the next step to get type hinting in the next PHP release,
regardless of whether strict or weak?

Best regards,
Christian

---

## #48821 — Stas Malyshev — 2010-06-17T19:14:08+00:00

URL: https://externals.io/message/48820#48821 · In reply to: #48820

Hi!

> I know the discussion is about scalar type hints. But what is with a
> object type hint as base for all objects?

When it makes sense to accept any object, regardless of the class, but 
not other types? I wonder if it's really a common use-case.
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

---

## #48822 — Christian Kaps — 2010-06-17T19:24:14+00:00

URL: https://externals.io/message/48820#48822 · In reply to: #48821

Am 17.06.2010 21:14, schrieb Stas Malyshev:
> Hi!
>
> > […]
>
> When it makes sense to accept any object, regardless of the class, but
> not other types? I wonder if it's really a common use-case.

My view layer accepts only presentation model objects. So every object
with public properties can be passed to the the view.

---

## #48826 — Melanie Rhianna Lewis — 2010-06-18T14:13:21+00:00

URL: https://externals.io/message/48820#48826 · In reply to: #48821

> Hi!
> 
> > […]
> 
> When it makes sense to accept any object, regardless of the class, but not other types? I wonder if it's really a common use-case.

Its useful in some patterns.  For example suppose you have a pattern where a class wraps another class.  The wrapped class could be *any* class if you're modify the behaviour of some default methods (say doing something like a decorator pattern).  Having a type hint that recognises object vs non objects is useful.

Melanie

---

## #48827 — Lukas Kahwe Smith — 2010-06-18T14:28:31+00:00

URL: https://externals.io/message/48820#48827 · In reply to: #48826

> 
> 
> 
> 
> > […]
> 
> Its useful in some patterns.  For example suppose you have a pattern where a class wraps another class.  The wrapped class could be *any* class if you're modify the behaviour of some default methods (say doing something like a decorator pattern).  Having a type hint that recognises object vs non objects is useful.


isnt this what interfaces are for?

regards,
Lukas Kahwe Smith
mls@pooteeweet.org

---

## #48828 — Christian Kaps — 2010-06-18T16:13:33+00:00

URL: https://externals.io/message/48820#48828 · In reply to: #48827

On Fri, 18 Jun 2010 16:28:31 +0200, Lukas Kahwe Smith <mls@pooteeweet.org>
wrote:
> 
> 
> > […]
recognises
> > […]
> 
> 
> isnt this what interfaces are for?
> 
> regards,
> Lukas Kahwe Smith
> mls@pooteeweet.org

Sure, you can create an empty interface for this scenario but only for
self defined classes. All PHP classes can't used with this interface.

---

## #48829 — Lukas Kahwe Smith — 2010-06-18T16:18:23+00:00

URL: https://externals.io/message/48820#48829 · In reply to: #48828

> On Fri, 18 Jun 2010 16:28:31 +0200, Lukas Kahwe Smith <mls@pooteeweet.org>
> wrote:
> > […]
> recognises
> > […]
> 
> Sure, you can create an empty interface for this scenario but only for
> self defined classes. All PHP classes can't used with this interface.


and you seriously need type hints for this use case?

regards,
Lukas Kahwe Smith
mls@pooteeweet.org

---

## #48830 — Richard Quadling — 2010-06-18T16:18:24+00:00

URL: https://externals.io/message/48820#48830 · In reply to: #48826

>
>
> 
>
> > […]
>
> Its useful in some patterns.  For example suppose you have a pattern where a class wraps another class.  The wrapped class could be *any* class if you're modify the behaviour of some default methods (say doing something like a decorator pattern).  Having a type hint that recognises object vs non objects is useful.
>
> Melanie
>
>
>
> --
> 
> 
>
>

class::method(object $instance)

would certainly be useful.

Could this not be solved by internally extending all userland classes
(and whilst we are at this why not all internal classes) from a PHP
supplied empty class? Maybe stdClass?

scalar, array, class, interface, untyped class.

-- 
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
