Abstracts in PHP4

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Abstracts in PHP4

Post by superdezign »

I'm writing a class for public use, so I'd like to give a PHP4 version as well. However, the abstract has an abstract function... How do I show this through PHP4?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

PHP 4 doesn't support abstract, public, private, protected, static and a few other keywords.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

I know, I was wondering how I could somehow let PHP 4 developers know that it was an abstract, but now I've decided just to not include a PHP 4 alternative. I'll just inform them on how to convert PHP 5 script into PHP 4 scripts.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If you're going to do that, you may as well provide it for them.

Generally I create a dummy class for PHP 4 with either empty or trigger_error() filled methods.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Horrible, but:

Code: Select all

/* abstract */ class MyAbstract {

/* abstract */ function myFunction () {
    trigger_error("Abstract function MyAbstract::myFunction not declared.", E_USER_ERROR);
}

}
(#10850)
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

Some people love to put c++ "pure virtual function called" spell in there, sounds kinda cool. ;)
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

arborint wrote:Horrible, but:

Code: Select all

/* abstract */ class MyAbstract {

/* abstract */ function myFunction () {
    trigger_error("Abstract function MyAbstract::myFunction not declared.", E_USER_ERROR);
}

}

I like that approach. Thanks for that.
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

You can also use docblocks which is handy since IDE's can also catch it

Code: Select all

/**
 * My class is cool
 *
 * @abstract
*/
class MyAbstractClass
{

}
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Bedby, can you explain what that has to do with imitating abstracts in php4?
Post Reply