PHP
php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*I am facing a problem with this code in line 29. Its printing "woof Voice of dog is" instead of " Voice of dog is woof. Can anyone help??*/"<br /> <br />"
<?php
{
class animal{
public $name;
public $age;
public $voice;
function speak(){
echo $this -> voice;
}
function __construct($name, $age){
$this -> name = $name;
$this -> age = $age;
}
}
$dog = new animal("tom",3);
echo "name of dog is ".$dog->name."<br />";
echo "Age of dog is ".$dog->age."<br />";
$dog -> voice = "woof";
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run