Page 1 of 1

variable declaration

Posted: Fri Sep 25, 2009 5:48 am
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? 
 

Re: variable declaration

Posted: Fri Sep 25, 2009 7:04 am
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.

Re: variable declaration

Posted: Fri Sep 25, 2009 7:47 am
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
 

Re: variable declaration

Posted: Fri Sep 25, 2009 7:49 am
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

Re: variable declaration

Posted: Fri Sep 25, 2009 9:36 am
by jackpf
lol. learn to read ;)