php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27255 Code declaration order
Submitted: 2004-02-14 16:53 UTC Modified: 2004-02-14 17:32 UTC
From: minimoose at balpoint dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.0b4 (beta4) OS: Windows XP Professional
Private report: No CVE-ID: None
 [2004-02-14 16:53 UTC] minimoose at balpoint dot com
Description:
------------
The order in which php code (a class) is declared and referenced in the sourcefile causes a compile error if not properly considered.

In PHP 4, declaring a class after referencing it posed no problem. In PHP 5 it generates a compile error.

Reproduce code:
---------------
<?php
$myinst = new myClass();
echo $myinst->myvar;

class myClass {
  public $myvar;

  function __construct()
  {
    $this->myvar = "initial value";
  }
}
?>

Expected result:
----------------
"Initial value"  should be printed to the output window/page/console.

Actual result:
--------------
<b>Fatal error</b>:  Class 'myClass' not found in <b>C:\myClass.php</b> on line <b>2</b><br />

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-14 17:32 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Just one of the changes with PHP 5.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 27 08:00:03 2025 UTC