<?php

// a) 

class LongName {

	var $firstname = " ";
	var $middlename = " ";	
	var $lastname = " ";
	
	function firstname($string) {	
	echo "First Name :	". $string;	
	}
	
	function middlename() {
	
	if (middlename){	
					    echo "Middle Name :  ". $this -> middlename;
                        } 
						else 
						{
						echo "Middle name, what is that? ";
					}
	}
	
	function lastname() {
	echo "Last Name	: ". $this -> lastname;
	}
	
}

	// b)
	
	class Firstname2 extends LongName {
	function firstname()
		{	
		echo "First Name: ".$param;
		}	
	}

	// c)

	class lastname2 extends LongName {
	function lastname()
		{
		echo "Last Name: ".$param;
		}
	}

	// d)
	

	$firstname = new LongName;
	$LongName -> firstname = 'David';

	$lastname = new LongName;
	$LongName -> lastname = 'Gunarso';
	
	$firstname = new firstname2;
	$firstname2 -> firstname = 'David';
	
	$lastname = new lastname2;
	$lastname2 -> lastname = 'Gunarso';
	
		
?>

Strict Standards: Declaration of Firstname2::firstname() should be compatible with that of LongName::firstname() in C:\xampp\htdocs\php_exercise\exercise2_3.php on line 39

Strict Standards: Creating default object from empty value in C:\xampp\htdocs\php_exercise\exercise2_3.php on line 54

Strict Standards: Creating default object from empty value in C:\xampp\htdocs\php_exercise\exercise2_3.php on line 60

Strict Standards: Creating default object from empty value in C:\xampp\htdocs\php_exercise\exercise2_3.php on line 63


Many errors. Why? I basically trying to call the function and want to see outputs.

Thanks before.

your code

#
$firstname = new LongName;
#
$LongName -> firstname = 'David';

try:

$firstname = new LongName();
	$LongName =$firstname->firstname('David');

here is an example of your code:

<?php

// a) 

class LongName {

	var $firstname = " ";
	var $middlename = " ";	
	var $lastname = " ";
	
	function firstname($name) {	
	echo "First Name :$name";	
	}
	
	function middlename($name) {
	
	if (middlename){	
					    echo "Middle Name :  $name";
                        } 
						else 
						{
						echo "Middle name, what is that? ";
					}
	}
	
	function lastname($name) {
	echo "Last Name	: $name";
	}
	
}

	// b)
	
	class Firstname2 extends LongName {
	function firstname($name)
		{	
		echo "First Name: $name";
		}	
	}

	// c)

	class lastname2 extends LongName {
	function lastname($name)
		{
		echo "Last Name: $name";
		}
	}

	// d)
	
	$firstname = new LongName();
	$LongName =$firstname->firstname('David');
echo $LongName;
	
		
?>

it will show First Name: David

Thanks. It works!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.