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
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: hanskrentel at yahoo dot de
New email:
PHP Version: OS:

 

 [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: Wed Jul 03 09:01:29 2024 UTC