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
 [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: Sat Apr 20 12:01:28 2024 UTC