php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24822 order of function scope searching doesn't match docs
Submitted: 2003-07-26 17:09 UTC Modified: 2003-07-28 03:39 UTC
From: norny at yahoo dot com Assigned:
Status: Closed Package: Website problem
PHP Version: 5CVS-2003-07-26 (dev) OS: Windows XP
Private report: No CVE-ID: None
 [2003-07-26 17:09 UTC] norny at yahoo dot com
Description:
------------
According to http://www.php.net/ZEND_CHANGES.txt,

"WIth both constants and functions, if you don't specify a class context the current class will be searched first and if the search fails then the global scope will be searched. If you want to force PHP to only check the global scope you can use the main:: accessor."

The snap I just downloaded seems to be search global first then the class second. Main:: doesn't seem to exist.

Reproduce code:
---------------
<?php

function asdf() {
   echo 'global';
}

class FooClass {
  function asdf() {
    echo 'class';
  }
  function printFoo() {
    asdf(); // outputs 'global'
    self::asdf(); // outputs 'class'
    main::asdf(); // Fatal error: Class 'main' not found in C:\Apache2\htdocs\test.php on line 14
  }
}
$qwerty = new FooClass;
$qwerty->printFoo();
?>

Expected result:
----------------
The first call to asdf() in printFoo should produce 'class'. The second self::asdf() seems to be correct, and the main::asdf() should print 'global'

Actual result:
--------------
The first call to asdf() in printFoo() should print 'class', not 'global'. The main:: accessor doesn't seem to be known but ZEND_CHANGES.txt says it does exist.

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-27 08:50 UTC] stas@php.net
The text is out of date. Namespaces are officially dead for now.
 [2003-07-28 03:39 UTC] goba@php.net
Out of date text removed from site, now it redirects to the more up to date zend-engine-2.php file.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Aug 19 00:01:27 2024 UTC