php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41998 Undefined functions in classes
Submitted: 2007-07-15 08:29 UTC Modified: 2007-07-15 11:12 UTC
From: hamishcool3 at yahoo dot co dot uk Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.3 OS: Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: hamishcool3 at yahoo dot co dot uk
New email:
PHP Version: OS:

 

 [2007-07-15 08:29 UTC] hamishcool3 at yahoo dot co dot uk
Description:
------------
When functions are defined inside a class, the function seems to undefine itself outside the class.

Reproduce code:
---------------
<?php
class Cart {
    var $items;  // Items in our shopping cart

    // Add $num articles of $artnr to the cart

    function add_item($artnr, $num) {
        $this->items[$artnr] += $num;
    }

    // Take $num articles of $artnr out of the cart

    function remove_item($artnr, $num) {
        if ($this->items[$artnr] > $num) {
            $this->items[$artnr] -= $num;
            return true;
        } elseif ($this->items[$artnr] == $num) {
            unset($this->items[$artnr]);
            return true;
        } else {
            return false;
        }
    }
}
add_item(1,12);
print_r($this);
?> 

Expected result:
----------------
Cart Object (
	[items] => Array (
		[1] => 12
	)
)

Actual result:
--------------
Fatal error: Call to undefined function add_item() in F:\webdocs\cp.php on line 25

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-15 11:12 UTC] jani@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


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Aug 17 19:00:03 2025 UTC