Page 1 of 1

PHP variable defining syntax help

Posted: Mon Jul 27, 2009 6:09 am
by Basit
Hi to all 8) ,
hope every one is fine.Can any one tell me when we declare variable like this

var $ob_Status = "<pre>";

$ob_Status is a variable but what is var and did "<pre>" has a special meaning in PHP or its just a constant here

Also what is mean by underscore when we define variable like this

$Host_ , $Out_ , $Line_
and

$_Server, $_Port , $_State

please explain this statement that what its mean,how its work

var $ob_Data = array(array ( null, "HELO : \$_Host", 250) // 0
,array ( 4, "AUTH LOGIN", 334) // 1
,array ( null, "\$_Login", 334) // 2


Thanks in advance :wink:

Re: PHP variable defining syntax help

Posted: Mon Jul 27, 2009 6:19 am
by VladSun
Basit wrote:Can any one tell me when we declare variable like this

var $ob_Status = "<pre>";

$ob_Status is a variable but what is var and did "<pre>" has a special meaning in PHP or its just a constant here
You can use this form of "variable declaration" only in a class definition. Otherwise, simply skip the "var" part like this:

Code: Select all

$newVariable = 5;
Basit wrote: Also what is mean by underscore when we define variable like this

$Host_ , $Out_ , $Line_
It's not PHP specific, but developer's style specific. Feel free to choose your own naming convention, though there are some "best pratice" ones.
E.g.:
http://framework.zend.com/manual/en/cod ... style.html
Basit wrote:$_Server, $_Port , $_State
Probably you meant "$_SERVER", etc. Take a look at this:
http://us2.php.net/manual/en/reserved.variables.php

Re: PHP variable defining syntax help

Posted: Mon Jul 27, 2009 6:45 am
by Basit
Hi,
Thanks for the reply.You mean defining _ in the end like $Out_ is only a matter of style only and is same as $Out and Pre _ like $_Server means already defined variables.
Thanks :)