Reply to Re: classes and require ?

Your name:

Reply:


Posted by Toby A Inkster on 03/12/07 14:53

avlee wrote:

> I have a big class in one php file.
> I would like to divide it to many smaller files.

This cannot be done. It's a side-effect of the fact that you cannot
include the construct "?>...<?php" anywhere within a class definition. I
have seen it somewhere in the PHP manual, but can't find it this afternoon!

If you really want to spread your class methods over several files, you
can use inheritance and abstraction. e.g.

A.php:
<?php
abstract class A
{
public function foo() {}
public function bar() {}
}
?>

B.php:
<?php
require_once 'A.php';
abstract class B extends A
{
public function baz() {}
}
?>

C.php:
<?php
require_once 'B.php';
/*concrete*/ class C extends B
{
public function quux() {}
}
?>

test.php:
<?php
require_once 'C.php';
$c = new C;
$c->foo();
$c->bar()
$c->baz()
$c->quux()
?>

But this seems an awfully silly thing to do. There are many good reasons
to use abstract classes. This is not one of them.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!

[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

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