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 6819155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:16:20+00:00 2026-05-26T21:16:20+00:00

When I defined a function in a supertype and called without parent:: it gave

  • 0

When I defined a function in a supertype and called without parent:: it gave me and error teling me it’s undefined function. I am wondering if I should use parent:: each time or if I am doing something wrong somewhere else.

I have a class, named core, which has an escape() function for escaping strings
I am trying to call this function from subtypes.
all methods are static.

Right now I don’T think static methods are inherited. I call all the static superclass methods with

parent::mystaticmethod() 

now. Because static methods are not inherited.

  • 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-26T21:16:21+00:00Added an answer on May 26, 2026 at 9:16 pm

    use parent:: only when you are going to override function in your child class

    Best way to explain this is this example:

    class Parent {
        function test1() {}    
        function test2() {}
        function __construct() {}
    }
    
    class Child extends Parent {
        function test1() {}  // function is overrided
        function test3() {
            parent::test1(); // will use Parent::test1()
            $this->test1();  // will use Child::test1()
            $this->test2();  // will use Parent:test2()
        }
        function __construct() {
            parent::__construct() // common use of parent::
            ... your code.
        }
    }
    

    Practical example (static methods):

    class LoaderBase {
        static function Load($file) {
            echo "loaded $file!<br>";
        }
    }
    
    class RequireLoader extends LoaderBase {
        static function Load($file) {
            parent::Load($file);
            require($file);
        }
    }
    
    class IncludeLoader extends LoaderBase {
        static function Load($file) {
            parent::Load($file);
            include($file);
        }
    }
    
    LoaderBase::Load('common.php'); // this will only echo text
    RequireLoader::Load('common.php'); // this will require()
    IncludeLoader::Load('common.php'); // this will include()
    
    Output:
    loaded common.php!
    loaded common.php!
    loaded common.php!
    

    Anyways using parent:: is more useful in non-static methods.

    As of PHP 5.3.0, PHP implements a feature called late static bindings which can be used to reference the called class in a context of static inheritance.

    More information here http://php.net/manual/en/language.oop5.late-static-bindings.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user defined function in SQL called getBuisnessDays it takes @startdate and
i've a small user defined function in python, say fib(n), how do i use
I can't understand what causes a syntax error in a user defined function. This
I created a User Defined Function with VB.NET and want to use that function
Is there a way to call a User defined function without using dbo. before
I'm trying to learn and use SP(Stored Procedure) and UDF(User Defined Function) with MySQL
Is it possible to create and use a user defined function in a report
I was wondering if a user defined function will always needs a return() statement
what the built-in or user-defined function that I can use in Javascript or jQuery
When creating a user defined function is it bad to just automatically use the

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.