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!
Navigation:
[Reply to this message]
|