ID: 28814
User updated by: nospam0 at malkusch dot de
Reported By: nospam0 at malkusch dot de
Status: Bogus
Bug Type: Feature/Change Request
Operating System: Linux
PHP Version: 5.0.0RC3
New Comment:
> - Typhints are a shortcut for an 'instanceof' test.
I'll never use instanceOf in any OO Language. It's sign
for a bad design.
> - 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.
I don't want that. I want for example this:
class Node {
private $parent;
private $children = array();
public function setParent(Node $node) {
$this->parent = $node;
}
public function removeChild($childID) {
$this->children[$childID]->setParent(NULL);
unset($this->children[$childID]);
}
...
}
Or I simply want to have the possibility to use optional
Paramters and Type Hints:
class Foo {
public function setDate(Date $date = NULL) {
if (is_null($date)) {
$date = new Date(time());
}
...
}
> Typehints have a different usage!
The please tell me what usage they have!
I thaught they might bring PHP nearer to an strict
language, but if I have to do without NULL or the
possibility to use optional Parameters I can't use Type
Hints strictly. By the way in Java, OCL (and C++ I think
too), NULL can be passed as any Type.
Previous Comments:
------------------------------------------------------------------------
[2004-06-17 09:40:24] [EMAIL PROTECTED]
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!
------------------------------------------------------------------------
[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