CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2020
    Posts
    3

    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

  2. #2
    Join Date
    Apr 2020
    Posts
    3

    Re: Regarding PHP problem

    Quote Originally Posted by bintech21 View Post
    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

  3. #3
    Join Date
    Apr 2020
    Posts
    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
  •  





Click Here to Expand Forum to Full Width

Featured