<?php
class Details
{
var $property1;
var $property2;
function display($name, $age)
{
print "Your name is : $name<br>";
print "Your age is: $age<br>";
}
}
$obj = &new Details;
$obj->name = 'Jamie';
$obj->age = '13';
$obj->display($obj->name, $obj->age);
?>
Well, that would depend on what youâre planning on doing.
How does this look?
<?php
class User
{
public $forename;
public $surname;
}
class UserPrinter
{
public static function display(User $user){
echo 'Hello ', $user->forename, ', your surname is ', $user->surname;
}
}
$me = new User;
$me->forename = 'Anthony';
$me->surname = 'Sterling';
UserPrinter::display($me);
/*
Hello Anthony, your surname is Sterling
*/
What material are you using, have you tried the manual ? If youâre struggling with PHPâs OOP features, maybe you should start a little lower down and work your way up.
<?php
class Details
{
private $name;
private $age;
public function __construct($name, $age)
{
$this->name=$name;
$this->age=$age;
}
function display()
{
print "Your name is : $this->name<br>";
print "Your age is: $this->age<br>";
}
}
$obj = new Details('Jamie', 13);
$obj->display();
?>
What operating system are you using Jamie? If youâre using a Windows machine, you can install âwampserverâ, this will install a full web server for you.