RE: beginner needs help!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: Jay Blanchard [mailto:jay.blanchard@xxxxxxxxxxxxxxxxxxxxx]
> Sent: Thursday, May 12, 2005 9:37 PM


> > var $exportFile = "Export." . date("mdy") . ".txt";
> 
> > I seem to be able to use the date function is I am not starting the
> > declaration with "var", but then my program is not working correctly.
> [/snip]
>
> You may have to assemble it beforehand sort of ...
> 
> $exportFileName = "Export." . date("mdy") . ".txt";
> var $exportFile = $exportFileName;

May? You _have_ to. This behavior was introduced in PHP4 as the only non-PHP3 compatible OOP behavoir as far as I know. Nice spotted for a beginner Rochelle :-) I mean the "I´m not allowed to use a function call while declaring with var". 

Explanation:
PHP3 allowed one to use a function call while declaring a variable:

var $welcome_text = "Welcome " . get_username_from_db($loginname) . ". Today is " . date("l") . ", have a nice day";

As of PHP4 one _can´t_ use a function call when declaring a var, but _has_ to do as in Your example Jay:

var $welcome_text; 
$welcome_text = "Welcome " . get_username_from_db($loginname) . ". Today is " . date("l") . ", have a nice day";


Pay attention to this though: You _not_ suppose to use var to declare a variable unless it´s inside a class. I never really tested that before, but outside a class this won´t work:

<?
var $test = "hello";
echo $test; // returns nothing
?>

--
Med venlig hilsen / best regards
ComX Networks A/S
Kim Madsen
Systemudvikler/Systemdeveloper

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux