I understand that all PHP variables need to be preceded by a dollar sign (e.g. $someValue = 1), but why is this the case? Why was this design choice made?

The reason I ask is my girlfriend asked why when I mentioned that PHP variables need to begin with a dollar sign, and I realized I had no idea why this syntactic choice was made.

Any ideas?

  • 12
    Because PHP's creator didn't know how to write a parser. So a crutch was needed to identify identifiers.
    – ThomasX
    Commented Dec 14, 2011 at 7:23
  • @ThomasX - Haha you are probably right... I'm no fan of the C code base either (yikes)
    – Ben DeMott
    Commented Dec 14, 2011 at 7:51
  • I think that only who created PHP can answer to this question.
    – apaderno
    Commented Dec 14, 2011 at 9:35
  • 1
    I gues it is to encourage developer... everytime you put $ sign you're closer to your payment! Commented Dec 14, 2011 at 10:41
  • I'd be happy if I didn't have to use $this-> in front of every class variable and function.
    – Chloe
    Commented Apr 10, 2015 at 20:48

2 Answers 2


Well I'm really not a big fan of the $$$ either (I don't really care how much the variable costed). But it comes from perl.

Interpreted scripting languages like perl or php use the $ to quickly identify and parse out variables. It's just an optimization for the interpreter. But definitely not an optimization for the programmer!

  • How is it not an optimization for a programmer? - I can immediately identify variables and distinguish them from other constructs ..
    – johannes
    Commented Dec 14, 2011 at 9:22
  • I believe Larry Wall once said the $ in front of variables made it easier to extend Perl without breaking existing code. He could add new keywords that would not already be used as variables. It should be this article, but it's behind a paywall :-( Commented Dec 14, 2011 at 13:01
  • @johannes I can also immediately identify a variable in C even without the $ because I've memorized all the key words and functions have parenthesis after them.
    – JSideris
    Commented Dec 14, 2011 at 14:46
  • 1
    @Bizorke C probably has less keywords (didn't count them) but well, PHP has constants, without $, even though people usually use constants in UPERCASE. And well, once you know all keywords etc by heart you are advanced, getting there might be simpler with this visual assistance ... but then: This is a matter of taste. My assumption for an answer would be "copied from Perl" and "simpler to parse" aka. historic decision
    – johannes
    Commented Dec 14, 2011 at 16:11
  • @johannes I didn't say the $ was copied from perl, I said it comes from Perl; PHP is based on Perl. Yes it is preference. I dislike typing the $ every time and in many editors $ is not selected when you double click on the word (slows down copy/paste). Yes PHP has slightly more keywords than C, but my argument still applies to C++, java, etc. Key words are generally easy to memorize and are usually relatively consistent between languages. Also, PHP is not JUST for beginners. I program in PHP (and many other languages) every day, and I can tell you that the $ has done nothing but slow me down.
    – JSideris
    Commented Dec 15, 2011 at 4:34

PHP Was originally a meta-syntax that was parsed and simply dynamically called-into a compiled c-programs functions.
In this way you can think of it similar to a "shell" program for the "web"...
It's no wonder variables with $dollarsigns were used similar to shell variables.

When I was all of 12, and I was learning PHP 3... as my first programming language - having the $ made life so much easier. I knew what a variable was, but having a reminder in all of the source code I read made learning possible... not sure I'd be here today if I didn't start on PHP.

Here's an example from -> http://www.php.net/manual/en/history.php.php

<!--include /text/header.html-->

<!--getenv HTTP_USER_AGENT-->
<!--ifsubstr $exec_result Mozilla-->
  Hey, you are using Netscape!<p>

<!--sql database select * from table where user='$username'-->
<!--ifless $numentries 1-->
  Sorry, that record does not exist<p>
<!--endif exit-->
  Welcome <!--$user-->!<p>
  You have <!--$index:0--> credits left in your account.<p>

<!--include /text/footer.html-->
  • 2
    While I don't doubt that the dollar sign was helpful to you, I wonder if maybe it was the overall simplicity of PHP that had more to do with it. I started with basic Javascript as a teenager and found variables pretty easy to learn, probably because the Javascript examples in those days were so simple. Commented Feb 26, 2013 at 1:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.