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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:43:18+00:00 2026-06-08T11:43:18+00:00

class A{ const FOO = 1; } class B extends A{ const FOO =

  • 0
class A{
  const FOO = 1;
}

class B extends A{

  const FOO = 5;

  function foo(){
    print self::FOO;
    print static::FOO;
  }
}

$b = new B;
$b->foo();

It prints 5 in both cases.

So there’s no difference in using static vs self on constants?

  • 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-06-08T11:43:20+00:00Added an answer on June 8, 2026 at 11:43 am

    In the context of Late Static Binding there is a difference.

    Consider this code:

    <?php
    
    class A {
        const FOO = 1;
    
        function bar() {
            print self::FOO;
            print "\n";
            print static::FOO;
        }
    }
    
    class B extends A {
        const FOO = 5;
    }
    
    $b = new B;
    $b->bar();  // 1 5
    

    If you run this code, the output will be:

    1
    5
    

    When referencing self::FOO, the value of 1 is printed (even though bar() was called on class B, but when the static keyword was used, late static binding took effect and it referenced the FOO constant from B rather than A when using the static keyword.

    This is relevant for PHP 5.3 and later.

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

Sidebar

Related Questions

lets say I have class : foo { public: static const foo Invalidfoo; foo();
I have the following situation: class Foo { public: static const Foo memberOfFoo; ........
I'm trying to export static fields from class: class Foo { const static int
I have a class template <typename Iterator, typename Value> class Foo { public: Foo(const
I am writing class with a const reference like this: class B; class foo
I have a class: class foo { private: std::string data; public: foo &append(const char*
I have this class package somePackage { public class SomeClass { public static const
I have a class which has a static const array, it has to be
Assuming you have a constant defined in a class: class Foo { const ERR_SOME_CONST
Given a class like this: class Foo { public: Foo(int); Foo(const Foo&); Foo& operator=(int);

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.