php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #33831 include does not work within class() {}
Submitted: 2005-07-23 01:52 UTC Modified: 2005-07-23 09:30 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: hanskrentel at yahoo dot de Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 4.4.0 OS: win32
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
42 + 48 = ?
Subscribe to this entry?

 
 [2005-07-23 01:52 UTC] hanskrentel at yahoo dot de
Description:
------------
the include() and require() statements do not work within the class() {} block. that's really a pitty, because it would be nice to put some function out of the class main file to make it easier to maintain larger class files.

this is not new. but there is a new scenario not in the database:

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

this seems to be a real bug in some cases. even if include works within a function statement within a class statement, it can not close this functions code-block even if it does. so this does not "works as expected" as stated by ernest at vogelsinger dot at.

you get no error in that kind of code but the function is not defined at all:

class_a.php:
<?
class A
{

	function B ()
	{
		include('class_a_c_method_tricky.php');

		/* code of function Ctricky */
	}
}
?>

class_a_c_method_tricky.php:
<?
	/* code of function B */
}

function C ()
{
	/* code of function C */
}

function Ctricky()
{
?>

the include is done (no error), but class A->C() is not defined. something is messed up here.

Reproduce code:
---------------
class.foo.php:
<?
class foo() {

  function foo() {
    $this->that = 'whatever';
  }

  include('class.foo-functions.php');
}

$c = new foo();
$c->fob();

?>

class.foo-functions.php:
<?
  function fob() {
   echo 'fob';
  }
?>

Expected result:
----------------
fob

Actual result:
--------------
Parse error: parse error, unexpected T_REQUIRE, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in [...]

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-23 09:30 UTC] tony2001@php.net
Class methods are evaluated at compile time and cannot be added during runtime.
That's well documented (http://php.net/manual/en/language.oop.php) and that's how it works.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 05 18:01:32 2024 UTC