variable declaration

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ranjitbd
Forum Newbie
Posts: 24
Joined: Sun May 03, 2009 1:59 pm

variable declaration

Post by ranjitbd »

Code: Select all

 
//what is the difference between following lines of code
var $abc = 10;
//and
     $abc = 10;
// var keyword is necessary or not to declare a variable? 
 
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: variable declaration

Post by Mark Baker »

Code: Select all

var $abc = 10;
was how a class attribute was declared in PHP 4. It has now been superceded in PHP5 by public, private or protected; although var is still treated as a synonym for public.
ranjitbd
Forum Newbie
Posts: 24
Joined: Sun May 03, 2009 1:59 pm

Re: variable declaration

Post by ranjitbd »

Code: Select all

 
<?php
var $abc = 10 ; // this is line 2
function test()
{
     global $abc;
     echo $abc;
}
test();
?>
//it showing following error
//Parse error: parse error in C:\xampp\htdocs\variableTest.php on line 2
// i am using php 5.2.29 version
 
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: variable declaration

Post by Mark Baker »

Code: Select all

var $abc = 10;
was how a class attribute was declared in PHP 4

You're trying to use var outside of a class
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: variable declaration

Post by jackpf »

lol. learn to read ;)
Post Reply