Fucntions!


#1

Here lies me code for PHP Functions II lesson 8.

I get the green light to move ahead, yet keeps displaying this in the printout:
"Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION on line 26"

What is the problem here?









<?php
class Dog {
public $numLegs = 4;
public $name;

    public function __construct($numLegs, $name) { 
        $this -> name1 = $name;
        $this -> name2 = $name;

    function bark() {
        return "Woof!";
    }
    function greet() {
        return "I'm " . $this->name . " " . " , a dumbshit dog! ";
    }
    }
    
    $dog1 = new Dog("Barker");
    $dog2 = new Dog("Amigo");
    
       echo $dog1 = bark("Barker");
       echo $dog2 = greet("Amigo");
    
    ?>
  </p>
</body>


#2

Here I have comment where you went wrong. Feel free to holla back if you don't get anything

<?php
	class Dog {
		
		//Here we have two class properties
		public $numLegs;
		public $name;
		
		//This is the constructor of the class
		//this tells you how to create objects using this class
		//here it takes two arguments
    	public function __construct($name,$numLegs) {
			
			//here we are saying the whatever argument a user
			// will pass when creating an object should be stored in 
			//the class' properties
			// so that whatever we create can use the methods of the class
        	$this -> name = $name;
        	$this -> numLegs = $numLegs;
			
		}// you forgot to add this closing brace

    	function bark() {return "Woof!";}
		function greet(){return "I'm " . $this->name . " " . " , a dumbshit dog! ";}
    }
    
	//we now creae two instances(objects) of that class
	//remeber when we create it, the format must follow that of the
	//constructor
    $dog1 = new Dog("Barker", 4);
    $dog2 = new Dog("Amigo",2);

	//the greet() and the bark() methods as defined do not
	//take in any arguments
    echo $dog1->bark();
    echo $dog2->greet();
    
?>

But the instructions probably want this

<?php
	class Dog {
		
		//Here we have two class properties
		public $numLegs=4;
		public $name;
		
		//This is the constructor of the class
		//this tells you how to create objects using this class
    	public function __construct($name) {
			
			//here we are saying the whatever argument a user
			// will pass when creating an object should be stored in 
			//the class' properties
			// so that whatever we create can use the methods of the class
        	$this -> name = $name;
			
		}// you forgot to add this closing brace

    	function bark() {return "Woof!";}
		function greet(){return "I'm " . $this->name . " " . " , a dumbshit dog! ";}
    }
    
	//we now creae two instances(objects) of that class
	//remeber when we create it, the format must follow that of the
	//constructor
    $dog1 = new Dog("Barker");
    $dog2 = new Dog("Amigo");

	//the greet() and the bark() methods as defined do not
	//take in any arguments
    echo $dog1->bark();
    echo $dog2->greet();
    
?>

#3

Ok, cool. I see where I went wrong. Thanks for your help.