note 80480 added to function.get-parent-class
| From: | biaggi at gmail dot com | Date: | Fri, 18 Jan 2008 11:59:54 +0000 |
| Subject: | note 80480 added to function.get-parent-class | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135187@lists.php.net to get a copy of this message | ||
I have a problem a class.
if we have two classes:
<?php
class a {
function a () {
if (get_class($this) == 'b') {
return NULL;
} else {
return parent::a();
}
}
}
class b extends a {
}
$bObj = new b();
$bObj->a();
?>
The problem is that I get an error:
PHP Fatal error: No parent class available in [file] on line [line]
I've solved the problem writing new class, so the code would read:
<?php
class a {
function a () {
return NULL;
}
}
class c extends a{
function a () {
if (get_class($this) == 'b') {
return NULL;
} else {
return parent::a();
}
}
}
class b extends c {
}
$bObj = new b();
$bObj->a();
?>
There is another solution on this problem?
----
Server IP: 130.206.1.5
Probable Submitter: 80.35.196.234
----
Manual Page -- http://www.php.net/manual/en/function.get-parent-class.php
Edit -- https://master.php.net/note/edit/80480
Del: integrated -- https://master.php.net/note/delete/80480/integrated
Del: useless -- https://master.php.net/note/delete/80480/useless
Del: bad code -- https://master.php.net/note/delete/80480/bad+code
Del: spam -- https://master.php.net/note/delete/80480/spam
Del: non-english -- https://master.php.net/note/delete/80480/non-english
Del: in docs -- https://master.php.net/note/delete/80480/in+docs
Del: other reasons-- https://master.php.net/note/delete/80480
Reject -- https://master.php.net/note/reject/80480
Search -- https://master.php.net/manage/user-notes.php