|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-07-15 11:12 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 16:00:02 2025 UTC |
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