-
April 20th, 2020, 06:01 AM
#1
Regarding PHP problem
Hi,
I have two classes 1) Person 2) Greeter I want to achieve followings how could i do that any help wih code example towards resolution of this is very much appreciated:-
1) Create an instance of class Person by passing a name to its constructor.
2) Create an instance of class Greeter by passing the Person instance from step 1 to its constructor.
3) Call the greetSubject() method on the Greeter instance from step 2.
4) The greetSubject() method uses the getName() method on its own $subject field.
***************
1) Person:-
<!DOCTYPE html>
<html>
<body>
<?php
class Person {
public $name;
function __construct($name) {
$this->name = $name;
}
function get_name() {
return $this->name;
}
}
$David = new Person("David");
echo $David->get_name();
echo "<br>";
?>
</body>
</html>
*********************************
2) Greeter:-
<!DOCTYPE html>
<html>
<body>
<?php
class Greeter {
public $subject;
function __construct($subject) {
$this->subject = $subject;
}
function get_subject() {
return $this->subject;
}
}
$science = new Greeter("science");
echo $science->get_subject();
?>
</body>
</html>
*******************************************
Thanks
-
April 20th, 2020, 08:34 AM
#2
Re: Regarding PHP problem
Originally Posted by bintech21
Hi,
I have two classes 1) Person 2) Greeter I want to achieve followings how could i do that any help wih code example towards resolution of this is very much appreciated:-
1) Create an instance of class Person by passing a name to its constructor.
2) Create an instance of class Greeter by passing the Person instance from step 1 to its constructor.
3) Call the greetSubject() method on the Greeter instance from step 2.
4) The greetSubject() method uses the getName() method on its own $subject field.
***************
1) Person:-
<!DOCTYPE html>
<html>
<body>
<?php
class Person {
public $name;
function __construct($name) {
$this->name = $name;
}
function get_name() {
return $this->name;
}
}
$David = new Person("David");
echo $David->get_name();
echo "<br>";
?>
</body>
</html>
*********************************
2) Greeter:-
<!DOCTYPE html>
<html>
<body>
<?php
class Greeter {
public $subject;
function __construct($subject) {
$this->subject = $subject;
}
function get_subject() {
return $this->subject;
}
}
$science = new Greeter("science");
echo $science->get_subject();
?>
</body>
</html>
*******************************************
Thanks
Any updates by experts please?
Thanks
-
April 21st, 2020, 02:43 AM
#3
Re: Regarding PHP problem
Are there any experts to help on the same please?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|