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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:40:21+00:00 2026-06-18T11:40:21+00:00

I try to call a member variable of a class from inside a method

  • 0

I try to call a member variable of a class from inside a method of the same class.

If I call it directly it doesn’t work, it requires to use the $this. Is there a reason for this? Can’t the class realize that the variable I am calling belongs to it?

  • 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-18T11:40:22+00:00Added an answer on June 18, 2026 at 11:40 am

    The reason is more or less just because that’s how PHP works. It sounds like you are used to Java which automatically uses instance members in the current scope if there is not a local variable that overrides the member in the same scope. PHP does not grant you this liberty:

    class x {
        private $y = 'r';
    
        public function z() {
            $y = 'q';
            echo "$this->y\n"; //r
            echo "$y";         //q
        }
    }
    

    In Java, you would still have to use this.y in the above example to print r because the class member name has been overridden locally. Just imagine that PHP’s members are always overridden in methods by void.

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

Sidebar

Related Questions

I try to use a abstract class type as a member variable in my
whenever I try to call my ejb from a client, I get this error
I am trying to use a vector as a member variable. GameOfLife.h class GameOfLifeManager
I try to call an API. I just want use active resource so I
I try to call the esriRegAsm.exe with arguments from a C# program. The purpose
When I try to call this simple function in a CFC, with the proper
for some reason when I try to call CocoaAsyncSocket's onSocket:didReadData:withTag method, it's failing and
Suppose I have a class Base which has a member variable A* my_hash. I
In a C++(03) class, I have a member variable, which must be assigned a
In this question creating a factory method when the compiler doesn't support new and

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.