|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-07-02 09:14 UTC] developer at libero dot it
Require nor Include works inner a class file.
This is the file where I define the class:
===== 1.php =====
<?
class test {
include("2.php"); //the same with require
}
?>
===== end =====
And this is the file where I have content.
===== 2.php =====
<?
var $a=1;
function method1 () {
$this->a++;
}
?>
===== end =====
This does not work.
The error is:
========
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}''
========
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 20:00:01 2025 UTC |
include is not allowed there, use the constructor instead class { function class () { include('2.php'); //same with require } }Well "include is not allowed there" is not sufficient. I have 200+ classes that have a common declaration of variables and methods. Everytime I need to modify this declarations I have to modify this 200+ files. If I could use require or include there I had only one file to modify. ----- Original Message ----- > ID: 11835 > Old-Status: Open > Status: Closed > Bug Type: Scripting Engine problem > > include is not allowed there, use the constructor instead > class { > function class () { > include('2.php'); //same with require > } > } > > > > Previous Comments: > --------------------------------------------------------------------------- > > [2001-07-02 09:14:57] developer@libero.it > > Require nor Include works inner a class file. > > This is the file where I define the class: > ===== 1.php ===== > <? > class test { > include("2.php"); //the same with require > } > ?> > ===== end ===== > > And this is the file where I have content. > ===== 2.php ===== > <? > var $a=1; > function method1 () { > $this->a++; > } > ?> > ===== end ===== > > This does not work. > The error is: > ======== > Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' > ======== > > --------------------------------------------------------------------------- >Did you try to define base class with common variables and functions? For example class Common { protected $strCommonVariable; protected function commonFunction() { ... } } class Specific extends Commmon { ... }