Re: Strange behaviour overriding methods in 5.0.4

From: Date: Wed, 28 Sep 2005 19:31:09 +0000
Subject: Re: Strange behaviour overriding methods in 5.0.4
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-223378@lists.php.net to get a copy of this message
Norbert Wenzel wrote:
Hi, i have a very strange example of code. Maybe you know where my mistake could be. I've got an index.php with a few div's and a short php code, like: <div>echo $_SESSION['view']->getContent();</div> The view is in every case one of my view objects. And there's the problem. In my specific case $_SESSION['view'] is of class "NoLoggedUserView", which of course extends "View". The "View" class containts a few public methods, namely
    getTitle()
    getHeadline()
    getSelection()
    getSubselection()
    getContentHeadline()
    getContent()
    getFunctions()
The child class "NoLoggedUserView" contains only the getContent()-method, which provides a login window. But of course I still call all the other methods like getTitle() in my index.php. Until yesterday I encountered no problems with that, but today, if i call $noLoggedUserView->getTitle() in the index.php i get an empty document. No error, no warning, no notice ... nothing. The page stays the same and doesn't change. Even the timestamp I print out to check if there has been a change, doesn't change. I tested a few things: The page loads fine and without any problems, if the public method getTitle() is written in the NoLoggedUserView and the method returns a stupid string. If getTitle() in NoLoggedUserView looks like this
did you try letting the parent class method just return a string constant?
    public function getTitle() {
        return parent::getTitle();
    }
there is the same problem as before. I get an empty page, no changes are made. My current version of getTitle() looks like this:
current version in NoLoggedUserView I presume, whats the definition in the parent class?
    public function getTitle() {
        //return 'NoLoggedTitle'; // works great
        //return parent::getTitle(); // no changes are made
what if there is no parent?
                       $classname = get_parent_class($this);
        $v = new $classname();
now just imagine if: $classname === false
        return $v->getTitle(); // works great
    }
And again, this strange thing works. So what could cause php to act like this? Any ideas or suggestions or at least assumptions? Please, I really don't know where to search the mistake..
use a shed load of echo(), print_r() and/or var_dump() to see what stufff is and how far along the execution gets - I do it now and again when I have bumped into another segfault. i.e. do stuff like echo 1,"<br>"; // your code here echo 2,"<br>"; // your code here echo 3,"<br>";


« previous php.general (#223378) next »