Hello,
I try to create a simple OOP PHP that shows an error:
class_lib.php
<?php
class person {
var $name;
function __constructor($person_name){
echo "Initialize class";
}
function set_name($new_name){
$this->name($new_name);
}
function get_name($new_name){
return $this->name($new_name);
}
function __destructor(){
echo "end class";
}
}
?>
program3.php
<?php include("class_lib.php"); ?> <?php
$stefan = new person();
$jimmy = new person();
$stefan->set_name();
$jimmy->set_name();
echo "Stefan Full Name : ".$stefan->get_name();
echo "Jimmy Full Name : ".$jimmy->get_name();
?>
Fatal error: Uncaught ArgumentCountError: Too few arguments to function person::set_name(), 0 passed in C:\xampp\htdocs\TEST\program_3_OOP_PHP.php on line 10 and exactly 1 expected in C:\xampp\htdocs\TEST\class_lib.php:14 Stack trace: #0 C:\xampp\htdocs\TEST\program_3_OOP_PHP.php(10): person->set_name() #1 {main} thrown in C:\xampp\htdocs\TEST\class_lib.php on line 14
line 14: function set_name($new_name){
I am following this tutorial: https://belajarphp.net/belajar-konsep-oop-php/
Thanks in advance.
Can anyone help me fix the error?