Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Scalar type hinting for PHP
C PHP
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
tests
.gitignore
README.md
config.m4
php_scalar.c
php_scalar.h

README.md

php-scalar

Scalar type hinting for PHP

function foo(int $bar) {
    echo "bar is $bar\n";
}
foo(123); // works
foo(4.56); // throws an error

Types:

  • bool
  • int
  • float
  • num (either int of float)
  • string
  • scalar (any of the above types)
  • object (of any class)
  • resource

Note that you cannot specify default values for scalar types because the parser doesn't support it.
This extension was a quick and dirty proof-of-concept. A proper implementation will require altering the parser which can't be done from an extension (without stupid amounts of work).

Something went wrong with that request. Please try again.