Reply to Re: Abstract classes

Your name:

Reply:


Posted by ZeldorBlat on 07/02/07 21:45

On Jul 2, 4:52 pm, Craig Taylor <ctalk...@gmail.com> wrote:
> I've got an abstract class:
>
> abstract class dbTable {
> abstract static function fn1();
> static function update()
> {
> // blah
> $var = self::fn1();
> // blah
> }
>
> }
>
> And then sombody that uses it:
>
> static class example extends dbTable {
> static function fn1( ) { // blah
> }
>
> static fn2()
> {
> self::update();
> }
>
> }
>
> The problem I'm running into is that the self::fn1() reference in the
> abstract class is failing with a Cannot call abstract method fn1()
> when I try to invoke it indirectly through dbTest.
>
> Note: I do want them to be static classes as the lifetime of the usage
> is not worth creating an object, calling 1 function, and then
> destroying it.

static methods are not inherited. In fact, as of PHP5, you'll get a
warning if you try to define a method as "abstract static." The
symbol "self" is bound at compile time -- basically it gets replaced
with whatever the class name is -- so, inside dbTable, self is turned
into dbTable. When you call fn1 from inside update, you're basically
calling dbTable::fn1 and, since that method is abstract, it can't be
called.

[Back to original 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

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