Edit report at http://bugs.php.net/bug.php?id=11835&edit=1

 ID:               11835
 Comment by:       tbiegacz at gmail dot com
 Reported by:      developer at libero dot it
 Summary:          Include and Require does not work inner a class
                   definition.
 Status:           Closed
 Type:             Bug
 Package:          Scripting Engine problem
 Operating System: win nt 4
 PHP Version:      4.0.4pl1

 New Comment:

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 {

 ...

}


Previous Comments:
------------------------------------------------------------------------
[2002-06-05 11:55:34] lopez at sydel dot net

Indeed include or class must work inside a class so as to ease multiple
definitions of the same variables or functions.  As in my case, all my
classes have a save and a delete function which are identical.  include
or require will make it easier for me to maintain my code (as what it
should be)

------------------------------------------------------------------------
[2001-07-02 09:27:12] developer at libero dot it

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] develo...@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 `'}'' 

> ========

> 

>
---------------------------------------------------------------------------

> 

------------------------------------------------------------------------
[2001-07-02 09:19:33] j...@php.net

include is not allowed there, use the constructor instead

class {

        function class ()       {

                include('2.php'); //same with require

                }

        }





------------------------------------------------------------------------
[2001-07-02 09:14:57] 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 `'}'' 

========

------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=11835&edit=1

Reply via email to