|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #11836 Require nor Include works inner a class file
Submitted: 2001-07-02 09:39 UTC Modified: 2015-09-07 17:56 UTC
Avg. Score:4.6 ± 0.7
Reproduced:6 of 6 (100.0%)
Same Version:1 (16.7%)
Same OS:2 (33.3%)
From: developer at libero dot it Assigned: cmb
Status: Closed Package: *General Issues
PHP Version: 4.0.4pl1 OS: ms nt 4
Private report: No CVE-ID:
 [2001-07-02 09:39 UTC] developer at libero dot it
Require nor Include works inner a class file.

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.

This is the file where I define the class, it's only a LITTLE example:

===== class_test.php =====
class test {
  var $b=0;
  var $c=1;
  function test() { //this is the constructor
    //some code here
  include("common_declarations.php"); //same with require
========  end  ========

And this is the file where I have the common declarations for 200+ files.

===== common_declarations.php =====
var $common_variable1=1;
function common_method1 () {
function common_method2 ($p=1) {
=====  end  =====

This does not work, the error is:

Parse error:  parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-07-02 09:41 UTC]
Not a bug, this was never supposed to work. making this a feature request.

 [2001-07-02 10:24 UTC]
Why don't you move your common variables and methods to a separate class, and have your 200 classes extend it?
 [2001-07-02 10:53 UTC] developer at libero dot it
It's a good idea. 
Thank you.
I still hope that require and include will works innner class declaration in future.
 [2001-07-02 11:01 UTC]
yes, actual knowledge of the coding technics one uses never did any harm.

I'll leave this suspended as it's a featrue request (and not very likely to get satisfied)
 [2015-09-07 17:56 UTC]
-Status: Suspended +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: cmb
 [2015-09-07 17:56 UTC]
Closing, because traits address this very issue and are available
as of PHP 5.4.0.
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 15:01:30 2015 UTC