note 26322 added to functions

From: Date: Sat, 26 Oct 2002 12:06:52 +0000
Subject: note 26322 added to functions
Groups: php.notes 
Request: Send a blank email to php-notes+get-38582@lists.php.net to get a copy of this message
To use class from function you need first to load class OUT the function and then you can use the class functions from your function example : 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; } else { return false; } } } ------------------------ <?php $cart = new Cart; function additem($var1,$var2){ $cart->add_item($var1, $var2); } additem(1,10); ?> -- http://www.php.net/manual/en/functions.php http://master.php.net/manage/user-notes.php?action=edit+26322 http://master.php.net/manage/user-notes.php?action=delete+26322 http://master.php.net/manage/user-notes.php?action=reject+26322

« previous php.notes (#38582) next »