Re: classes?

From: Date: Thu, 16 Nov 2000 06:56:28 +0000
Subject: Re: classes?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-25640@lists.php.net to get a copy of this message
Sure - it's easy. <? class Bike{ var $speed; var $brake; var $accel; function set_speed($new_speed){ $this->speed = $new_speed; } function return_speed(){ return $this->speed; } function set_brake($new_brake){ $this->brake = $new_brake; } function return_brake(){ return $this->brake; } // This is a constructor // You can pass functions to this // also. function Bike(){ $this->set_brake(0); $this->set_speed(0); } function SpeedUp($speed){ $this->set_speed(++$this->speed); } function Brake($pressure){ $this->set_speed(($this->speed - $pressure)); } } ?> Then you create a bike: <? $bike = new Bike(); $bike->SpeedUp(3); $bike->Brake(1); $current_speed = $bike->return_speed(); echo $current_speed; ?> The result will be 2 --Joe On Thu, Nov 16, 2000 at 01:16:59AM -0500, Kurth Bemis wrote: > ok all i'm just starting to get involved with classes...and have a slight > problem......i don't understand how to access functions..i have been > reading the manual at php.net but that confuses even more....take a look at > some code i wrote... > > print "<a href=\"$PHP_SELF?product=$product&quanity=1\">$title - > $price</a>"; > > thats to add a item to my cart...... > > the class function looks like this... > > function add_item($table, $session, $product, $quantity) { > $qty = $this->check_item($table, $session, $product); > if($qty == 0) { > $query = "INSERT INTO $table (session, product, quantity) > VALUES "; > $query .= "('$session', '$product', > '$quantity') "; > mysql_query($query); > } else { > $quantity += $qty; > $query = "UPDATE $table SET quantity='$quantity' WHERE > session='$session' AND "; > $query .= "product='$product' "; > mysql_query($query); > } > } > > my question is how to i pass that vars that i need to the class? am i > making sense here? > > ~kurth > Kurth Bemis - Network/Systems Administrator, USAExpress.net/Ozone Computer > > There is no sin except stupidity. -- Oscar Wilde > > kurth@usaexpress.net | http://www.usaexpress.net/kurth > PGP key available - http://www.usaexpress.net/kurth/pgp > > Fight Weak Encryption! Donate your wasted CPU cycles to Distributed.net > (http://www.distributed.net) > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net ================================================================================ = Joe Stump joestump98@yahoo.com http://www.miester.org = ================================================================================ "Real programmers don't comment their code. It was hard to write, it should be hard to understand."

« previous php.general (#25640) next »