php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10430 require() does not work inside class bodies (ie. to pull in methods)
Submitted: 2001-04-21 05:15 UTC Modified: 2001-04-29 13:37 UTC
From: cpoirier at shelluser dot net Assigned:
Status: Closed Package: *General Issues
PHP Version: 4.0.4pl1 OS: Window 98
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cpoirier at shelluser dot net
New email:
PHP Version: OS:

 

 [2001-04-21 05:15 UTC] cpoirier at shelluser dot net
In file class.php:
--------------------------------------------------------
<?php

class myclass
{
  require( $DOCUMENT_ROOT . "/methods.inc.php" );
}

$myinstance = new myclass;
$myinstance->method();
?>
--------------------------------------------------------

In file methods.inc.php:
--------------------------------------------------------
<?php
function method()
{
  print "hi";
}
?>
--------------------------------------------------------

Accessing class.php returns the following error:
Parse error:  parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in class.php on line 5

Surely this should work?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-04-29 13:37 UTC] andi@php.net
Right. require() and include() both happen at run-time while the class is checked for method's at compile-time. You have to include the method definitions inside the class {}

Andi
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 17 09:01:30 2024 UTC