php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #17987 require() not permitted within class definition
Submitted: 2002-06-26 00:30 UTC Modified: 2002-06-26 02:12 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: david-work at robinson-au dot net Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 4.2.0 OS: Windows 2000
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: david-work at robinson-au dot net
New email:
PHP Version: OS:

 

 [2002-06-26 00:30 UTC] david-work at robinson-au dot net
Hello


The include() and require() statements do not work within a class definition.

This may be a parsing problem, or it may behave as designed.

See below for an example script and the errors generated.

I am running the precompiled binary downloaded from the php.net website.


Many thanks
David Robinson



*** Example 1
<?PHP
class test
{
    function f1()
    {
        ...
    }

    include('file.php');

    function f2()
    {
        ...
    }
}
?>
*** End Example 1

*** Error 1
Parse error: parse error, unexpected T_INCLUDE, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' ...
*** End Error 1

*** Error 2
Parse error: parse error, unexpected T_REQUIRE, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' ...
*** End Error 2

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-26 00:48 UTC] alan_k@php.net
Sorry, but the bug system is not the appropriate forum for asking
support questions. Your problem does not imply a bug in PHP itself.
For a list of more appropriate places to ask for help using PHP,
please visit http://www.php.net/support.php

Thank you for your interest in PHP.

thats designed behaviour = put the include outside the class or inside the function/methods.
 
 [2002-06-26 01:04 UTC] david-work at robinson-au dot net
The class definition is very long, and I want to break the class definition into multiple files.

The first suggestion was to place the require() statement outside the class. This will not split the class definition into multiple files.

The second suggestion was to place the require() statement inside the function. Unfortunately this will separate the function definition and the function body into two separate files. This will result in less readable code.

Therefore I request that include() and require() statements be permitted inside a class definition, and between function definitions.

This modification is the most appropriate place to split a long class definition, and will also improve the flexibility of the php scripting.


Kind regards
David Robinson
 [2002-06-26 01:39 UTC] alan_k@php.net
It's unlikely IMHO to be added as it obfusicates the language.

You could consider using the aggregate features 
http://cvs.php.net/co.php/php4/ext/standard/aggregation.c?sbt=2&r=1.9&Horde=2e4f3fff0c858a39971b8eaf6cabbde2

Or PHP5 I believe will have multiple inheritance using aggregation

 [2002-06-26 02:12 UTC] derick@php.net
We can not possible fix the requires inside classes, the engine will not support this until there is a new design for it, which is unlikely to happen.

Derick
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 18:01:31 2024 UTC