I am trying to create a TestClass class divided into several files. I divided it into 3 files, where the first TestClassPart1.php file has the beginning of the class class TestClass { , and the last TestClassPart3.php file has the class closing bracket. These are 3 files
//TestClassPart1.php <?php class TestClass { public function func1(){ echo "func 1"; }
Then I recombine in the actual class file called TestClass.php , so TestClass.php is just the glue of all three files.
<?php require 'TestClassPart1.php'; require 'TestClassPart2.php'; require 'TestClassPart3.php';
I thought this should work, but when I try to instantiate TestClass and call one of the functions, I get parse error, expecting T_FUNCTION' in C:\wamp\www\TestClassPart1.php on line 5 . Line 5 is } of func1()
<?php require 'TestClass.php'; $nc = new TestClass(); $nc->func1();
Doesn't that work? I thought you could distribute the class across multiple files without a problem. Am I doing it wrong?
source share