#28814 [Opn->Bgs]: class type hints for function parameters to not allow the passing of NULL
ID: 28814
Updated by: helly@php.net
Reported By: nospam0 at malkusch dot de
-Status: Open
+Status: Bogus
Bug Type: Feature/Change Request
Operating System: Linux
PHP Version: 5.0.0RC3
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
- NOTHING stops you from passing NULL to functions.
- Typhints are a shortcut for an 'instanceof' test.
- now try NULL instanceof stdclass:
php-cvs $ php -r 'var_dump(NULL instanceof stdclass);'
bool(false)
- what you probably want is
function bla($x) {
if (is_null($x)) {
// handle null
} else if ($x instanceof whatever) {
// handle instance
} else {
// handle error
}
}
- if you look again you'll see that you are doing *three different*
things in your code. Typehints have a different usage!
Previous Comments:
------------------------------------------------------------------------
[2004-06-17 05:48:33] nospam0 at malkusch dot de
Description:
------------
Since RC3 I can't define optional parameters when I'm
using type hinting. Why is it no more allowed to use NULL.
Im used to do so from other OO Languages.
So if I have to live with no NULL and want to use class
Type hints, how can I use optional Paramters?
Reproduce code:
---------------
class Test {
public function test(Test $optinalTest = null) {
}
}
Expected result:
----------------
No Error, or a possibility to use class type hints *and*
optinal parameters. Perfect would be the old behavoir,
that I'm allowed to use NULL.
Actual result:
--------------
Fatal error: Argument 1 must not be null
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=28814&edit=1
Thread (4 messages)