This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Objects in PHP Forum

View Course » View Exercise

1021 points
55722e32937676af980004b6_457385943
Submitted by
Brigette Eckert
about 2 years ago

1.8 Missing Agrument 1?

"Woof!Missing argument 1 for Dog::greet(), called on line 28 and defined (line 19)Undefined variable: name (line 20)Hi, my name is and I like to play fetch" in display console. Not sure why it is not taking Barker and Amigo. Can someone help/explain please?

Here is my code.:

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

public function __construct($name) {
$this ->name = $name;
}
public function bark() {
return "Woof!";
}

public function greet($name) {
echo "Hi, my name is" . " " . $name . " and I like to play fetch";
}

    }

    $dog1 = new Dog("Barker");
    $dog2 = new Dog("Aimgo");
    echo $dog1 -> bark();
    echo $dog2 -> greet();
    ?>

ps this course has been super glitchy for me so I am trying to figure out if its a problem with my code or another glitch.


0 votes

permalink

That should do the trick! I would like to explain the way I see how it works but I'm not the greatest at that, but if you would like to know then let me know!

833 points
F7fcb27e417690c04069c7fb72b4a248?s=140&d=retro
Submitted by
Mk
about 2 years ago

2 Comments

55722e32937676af980004b6_457385943 Brigette Eckert about 2 years ago

the image you posted isn't loading.

F7fcb27e417690c04069c7fb72b4a248?s=140&d=retro Mk about 2 years ago

public function greet() {
echo "Hi, my name is " . $this->name . " and I like to play fetch";
}
Basically what the image was


0 votes

permalink

    class dog{
        public $numlegs=4;
        public $name;
        public function __construct($name) 
        {
            $this->name=$name;
        }
        public function bark(){
            return"woof";
        }
        public function greet(){
            echo "Hi, my name is " . $this->name . " and I like to play fetch";
        }
          $dog1=new dog("barker");
        $dog2=new dog("sunny");
        echo $dog1->bark();
       echo $dog2->greet();
    }


            please tell 

``Parse error: syntax error, unexpected TVARIABLE, expecting TFUNCTION on line 23
echo $dog->bark();

111 points
1f96b188244043de81be32d891b99e5e?s=140&d=retro
Submitted by
str111
about 2 years ago