0
<?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.

Edited by davy_yg: n/a

2
Contributors
3
Replies
6
Views
5 Years
Discussion Span
Last Post by davy_yg
0

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;
	
		
?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.