<?php
class person {
var $name; // variable inside class = property
function __construct($persons_name=null) {
$this->name = $persons_name;
}
function set_name($new_name) {
$this->name = $new_name;
}
function get_name() { // function inside class = method
return $this->name;
}
}
// Create object WITHOUT constructor by calling a method
$SecurityEngineer = new person();
$SecurityEngineer->set_name("Debbie B");
echo "<br>Debbie's full name: " . $SecurityEngineer->get_name()."<br>";
// Create object WITH a constructor
$WanEngineer = new person("Lisa L");
echo "Lisa's full name: " . $WanEngineer->get_name();
<br>Debbie's full name: Debbie B<br>Lisa's full name: Lisa L
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.2
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/15uV1 on line 3
<br>Debbie's full name: Debbie B<br>Lisa's full name: Lisa L
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9
<br>Debbie's full name: Debbie B<br>Lisa's full name: