PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have been using php for some time and I have developed a decent understanding, I'm now learning object orientated programming (OOP). Can someone explain the following code & how I can do the following in the most efficient way possible :
(i) - Initiate a new AutoMobile object, set the maximum speed to 200 & make it drive backwards.
(ii) - How would you remove all of the automobiles wheels?
class AutoMobile {
var $Wheels;
var $Speed;
var $Direction;
function Car() {
$this->Wheels = 4;
}
function MaxSpeed($int) {
$this->Speed = $int;
}
function goBackwards() {
$this->Direction = ‘backwards’;
}
function setWheels($int) {
$this->Wheels = $int;
}
}
<?php
class AutoMobile {
var $Wheels;
var $Speed;
var $Direction;
function Car() {
$this->Wheels = 4;
}
function MaxSpeed($int) {
$this->Speed = $int;
}
function goBackwards() {
$this->Direction = ‘backwards’;
}
function setWheels($int) {
$this->Wheels = $int;
}
}
?>
<?php
include('yourclass.php');
$a = new Automobile; //initiate the class
$a->MaxSpeed(200); //set max speed to 200
$a->goBackwards(); //make it go backwards
$a->setWheels(0); //remove all the wheels
?>