You are here: Re: [PHP] Strange behaviour overriding methods in 5.0.4 « PHP « IT news, forums, messages
Re: [PHP] Strange behaviour overriding methods in 5.0.4

Posted by Jochem Maas on 09/28/05 22:31

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>";

>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация