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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:43:22+00:00 2026-05-31T21:43:22+00:00

Today I saw a post on php.net, that I’m quoting here: $Bar = a;

  • 0

Today I saw a post on php.net, that I’m quoting here:

$Bar = "a";
$Foo = "Bar";
$World = "Foo";
$Hello = "World";
$a = "Hello";

$a; //Returns Hello
$$a; //Returns World
$$$a; //Returns Foo
$$$$a; //Returns Bar
$$$$$a; //Returns a

$$$$$$a; //Returns Hello
$$$$$$$a; //Returns World

Since PHP inherits its syntax from C++, doesn’t the dollar sign remind you of pointers?

string bar = "a";
string *foo = &bar;
string **world = &foo;
string ***hello = &world;
string ****a = &hello;

Just like pointers, when you define $a = 'var' and $var = 'test' and then you do $$a you are using the value of $a to point to $var which is kinda what happens with C++ pointers just with strings instead of memory addresses.

So can the dollar sign in PHP be related to C++ pointers?

  • 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-31T21:43:23+00:00Added an answer on May 31, 2026 at 9:43 pm

    Since PHP derives from C++…

    Stop. This line of thinking will get you nothing but pain and suffering. Perl, LPC, Lua, Pike, Ada 95, Java, PHP, D, C99, C#, and Falcon are all derived from C++ as well, for some definition of "derived", and I can guarantee you they act nothing like C++ and are certainly not used like C++ either. The similarities are superficial in nature, and their semantics are totally different.


    In the case you provided above, it’s more similar to languages like Javascript in the sense that you can resolve and dereference a variable name given only a string. In C++ knowing just the name of the variable doesn’t allow you to dereference the variable. What you need is its memory address (hence the & operator). That’s the key difference.

    I think the most salient point of misunderstanding here is this part of your question:

    Just like pointers, when you define $a = ‘var’ and $var = ‘test’ and
    then you do $$a you are using the R-value of $a to point to $var which
    is kinda what happens with C++ pointers.

    This isn’t explanation doesn’t capture the entire picture with regards to pointers. I assume you’re talking about things like these:

    PHP:

    $var = 'test' 
    $a = 'var'
    //$$a == 'test'
    

    C++:

    std::string var = "test";
    std::string* a = &var;
    // *a == "test";
    

    The big difference between the two is that C++’s a contains a memory address for the var variable, not a string containing the name of the variable var.

    It’s more like reflection than anything else, which C++ certainly does not have as standard, and thus cannot just simply dereference a variable given only a string name.

    From the PHP documentation for variable variables:

    Sometimes it is convenient to be able to have variable variable names.
    That is, a variable name which can be set and used dynamically. [emphasis mine]

    If C++ had that kind of functionality, it would be more like this:

    std::string Bar = "a"; 
    std::string Foo = "Bar"; 
    std::string World = "Foo"; 
    std::string Hello = "World"; 
    std::string a = "Hello"; 
    
    // Hypothetical function dyn_deref_str that gets the string value
    // held by a variable given only its name.
    a; //Returns "Hello"
    dyn_deref_str(a); //Returns "World" 
    dyn_deref_str(dyn_deref_str(a)); //Returns "Foo" 
    dyn_deref_str(dyn_deref_str(dyn_deref_str(a))); //Returns "Bar" 
    dyn_deref_str(dyn_deref_str(dyn_deref_str(dyn_deref_str(a)))); //Returns "a"
    

    This is very different from simple pointer dereferencing, as pointers do not hold strings, they hold memory addresses. Even though you shouldn’t be using pointers in your code anyway except in very specific circumstances.

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

Sidebar

Related Questions

I'm just starting to get into ASP.NET MVC, and saw today that the Beta
This is something curious that I saw in my coding today. Here is the
I saw this in some code today. class Foo def self.bar @myvar = 'x'
I saw a post earlier today and have been playing around with: http://arashkarimzadeh.com/index.php/jquery/7-editable-jquery-plugin.html What
I'm writing bug tracking software in PHP, and today I saw this in another
Today I saw a JavaScript syntax (when invoking a function) that is unfamiliar to
I've been working on PHP for some time but today when I saw this
Today, I got completely surprised when I saw that a global variable has undefined
Today i saw this bad code structure and since then i started to think
I saw this today in some PHP code: $items = $items ?: $this->_handle->result('next', $this->_result,

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.