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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 12:01:32 2025 UTC