Solved

Defining Variable without $

Posted on 2006-10-22
3
135 Views
Last Modified: 2006-11-18
Hello,

I want to set a variable in PHP without using $

Like this:

echo "Content" . _Footer;


How can I do this?

         _Footer = "Foobar"

Thanks!
0
Comment
Question by:hankknight
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 350 total points
ID: 17784912
>I want to set a variable in PHP without using $
you cannot. php variables use $.

you can however define constants:
http://php.net/define

define("_Footer", "Foobar");

echo "Content" . _Footer;
0
 
LVL 14

Assisted Solution

by:Aamir Saeed
Aamir Saeed earned 100 total points
ID: 17784993
Unlike with most other languages (a notable exception being Perl), PHP uses a special character to define a word as a variable. Variables in PHP are prefixed by a dollar sign ('$').

Variables do not require formal declaration. They will automatically be declared when a value is assigned to it. In the example below, the variable myvar, is assigned a string value:
$myvar = "Some string";

Variables are "loosely typed". This means that their type does not have to be fixed. The examples below are both valid. PHP determines the variable type in either case:
$myvar = "1";
$myvar = 1;
0
 
LVL 48

Assisted Solution

by:hernst42
hernst42 earned 50 total points
ID: 17787318
Other Option would be to recompile php and modify the php parser so the _ is the token for variables. Then the _ may not be used inside names.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question