FAQ
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

Search Discussions

  • Dmitri Snytkine at Dec 22, 2011 at 7:56 pm
    Numeric isnt' a type at all, it's some type of unicorn.
    Seriously, stop inventing new types because it will not make a language
    better, instead will give people valid reasons to critisize the language.
    Either add support for type hinting of all primitive types or don't add it,
    keep the language as is, but adding these new 'scalar' or 'numeric' is just
    a horrible idea.

    Dmitri Snytkine
    Web Developer
    Ultra Logistics, Inc.
    Phone: (888) 220-4640 x 2097
    Fax: (888) 795-6642
    E-Mail: dsnytkine@ultralogistics.com
    Web: www.ultralogistics.com

    "A Top 100 Logistics I.T. Provider in 2011"


    -----Original Message-----
    From: Christian Kaps
    Sent: Thursday, December 22, 2011 2:52 PM
    To: PHPMailingList
    Subject: [PHP-DEV] Scalar Type Hint

    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

    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: http://www.php.net/unsub.php
  • Will Fitch at Dec 22, 2011 at 8:05 pm
    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.
    On Dec 22, 2011, at 2:52 PM, Christian Kaps wrote:

    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

    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: http://www.php.net/unsub.php

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedDec 22, '11 at 7:52p
activeDec 22, '11 at 8:05p
posts3
users3
websitephp.net

People

Translate

site design / logo © 2022 Grokbase