# Scalar Type Hint

- Thread: https://externals.io/message/57026
- Original archive: https://news-web.php.net/php.internals/57026
- Started by Christian Kaps on 2011-12-22T19:52:21+00:00
- Messages: 2
- 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

---

## #57026 — Christian Kaps — 2011-12-22T19:52:21+00:00

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

Hi internals,

someone in the "Return Type Hinting for Methods RFC" thread had the idea 
of a "numeric" type hint. I will capture this idea and propose a 
"scalar" type hint. I understand the problem of the current discussion 
about scalar type hints(int, float, string, double, ...). But there 
should be a possibility to define a "scalar" type hint to restrict 
arguments to scalar types.

function setName(scalar $name) {}

class Foo {
     public function __toString() {}
}

setName(1) // pass
setName(true) //pass
setName('Christian') // pass
setName(new Foo) // pass
setName(array()) //fail
setName(new stdClass) //fail

Why this isn't possible?

Christian

---

## #57030 — Will Fitch — 2011-12-22T20:05:13+00:00

URL: https://externals.io/message/57026#57030 · In reply to: #57026

That's the way to do it.  If you have an idea, such as this, write it up, and let's discuss.  If we don't, we end up talking about things (like scalar type hinting) that has been beaten to death on more than 100 occasions (sarcasm, but not really...).  We can then have a reference to point to showing that the discussion is dead.  After 6 months, feel free to bring it up again.



> Hi internals,
> 
> someone in the "Return Type Hinting for Methods RFC" thread had the idea of a "numeric" type hint. I will capture this idea and propose a "scalar" type hint. I understand the problem of the current discussion about scalar type hints(int, float, string, double, ...). But there should be a possibility to define a "scalar" type hint to restrict arguments to scalar types.
> 
> function setName(scalar $name) {}
> 
> class Foo {
>    public function __toString() {}
> }
> 
> setName(1) // pass
> setName(true) //pass
> setName('Christian') // pass
> setName(new Foo) // pass
> setName(array()) //fail
> setName(new stdClass) //fail
> 
> Why this isn't possible?
> 
> Christian
