Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7088743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:50:18+00:00 2026-05-28T07:50:18+00:00

What is the difference between two codes? Extends; <?php require_once ‘example.class.php’; Class First extends

  • 0

What is the difference between two codes?

Extends;

<?php 
require_once 'example.class.php';
Class First extends Example
{}
?>

Normal calling;

<?php
require_once 'example.class.php';
Class First
{
    public $example;
    function __construct()
    {
        $this->example = new Example();
    }
}
?>

I know some difference for example using protected pharase.
But this is not enough in my opinion.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:50:18+00:00Added an answer on May 28, 2026 at 7:50 am

    The first one, the object First will have the same properties/functions of Example class. Like:

    class Example
    {
        public function a()
        {
        }
    }
    
    class First extends Example
    {
        public function b()
        {
        }
    }
    

    if you instance two objects $ex1, $ex2:

    $ex1 = new Example();
    $ex1->a(); // this is valid
    $ex1->b(); // this is invalid because Example doesn't have "b" function
    
    $ex2 = new First();
    $ex2->a(); // this is valid
    $ex2->b(); // this is valid too, because First inherits Example members + its own
    

    on the second code, you’re creating an instance of example so you must access that variable to be able to call Example method.

    one better example:

    class Person
    {
        public $name;
    
        public function say($message) 
        { 
            echo $this->name . " says " . $message;
        }
    }
    
    class Teacher extends Person
    {       
        public function say($message) 
        { 
            // note that Teacher has a name even this is not declared here.
            echo $this->name . " says " . $message; 
        }
    
        public function teach($what) 
        { 
            // note that Teacher has a name even this is not declared here.
            echo $this->name . " is teaching " . $what; 
        }
    }
    

    See the output:

    $john = new Person();
    $john->name = "John Doe";
    $john->say("hello world!");
    /* 
    $john->teach("Portuguese"); // invalid, person doesn't teach anything.
    */ 
    
    
    $chuck = new Teacher();
    $chuck->name = "Chuck Norris";
    $chuck->say("hello universe!");
    $chuck->teach("Fighting"); // valid because Teacher has method "teach"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the difference between this two codes? class SomeClass { SomeType val =
I've created a function to return the difference between two dates <?php class days
System.out.println(matcher.group(1)); System.out.println(matcher.group()); I like to know what's the difference between the above two codes.
How to calculate minute difference between two date-times in PHP?
I am feeling surprised by the difference between two seemingly identical scripts. first.ps1: A
Is there a difference between the two codes below, I presume not. function Agent(bIsSecret)
What is the difference between these two pieces of code? class something { static
What is the difference between Class.forName and ClassLoader.loadClass in the following codes: Class theClass
What are the differences between these two codes in JavaScript? var obj = new
What's the difference between the two code below. int a[] = {0,0}; int a[2]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.