Yii Framework Forum: PHP declare function - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

PHP declare function using variables inside declare Rate Topic: -----

#1 User is offline   blaxinix 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 27-May 12

Posted 06 July 2012 - 03:27 PM

Note: This is not a YII question but rather just simple php



I am creating a simple php code to get a date.

<?php $today = date('l \t\h\e jS');
define('TODAY','$today');

echo 'Today is '.TODAY.'' ;

?>

The above code does not work.

I am planing to get the value for $today variable in define function.

I can however do it simple way by just replacing TODAY in " echo 'Today is '.TODAY.'' ; " with $today..

But i want to know what variable is not working inside the define constant.

is that illegal ?
0

#2 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 06 July 2012 - 03:42 PM

/* Moved from Tutorials to Misc - General PHP */

http://php.net/manua...tion.define.php

Do not quote the variable, and don't use single-quotes for the constant:
define("TODAY", $today); 

"Less noise - more signal"
1

#3 User is offline   lucifurious 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 184
  • Joined: 15-March 09
  • Location:Atlanta, GA.

Posted 06 July 2012 - 05:40 PM

And you shouldn't be using define anyway. Class constants my boy!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users