freephoneid Posted June 19, 2008 Share Posted June 19, 2008 Hi, Can any one tell me why define is not working below: <?php include("lang/default/macro.php"); ?> <html> <head> <title><?=title?></title> </head> <body>Hello World</body> </html> My macro file contains following: <?php define("title","I'm great"); ?> It prints title as "?=title?" rather than reading it from macro.php. However below code works fine: <?php include("lang/default/macro.php"); ?> <html> <head> <title><? echo constant("title"); ?></title> </head> <body>Hello World</body> </html> I want to use the macro using <?=title?> format. Can any one help me????? Thanks!!! Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/ Share on other sites More sharing options...
DyslexicDog Posted June 19, 2008 Share Posted June 19, 2008 please post the code from your macro.php file. remember to use code tags when posting code please. Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569481 Share on other sites More sharing options...
hitman6003 Posted June 19, 2008 Share Posted June 19, 2008 It prints title as "?=title?" Short open tags is probably disabled. Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569483 Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 Why? Don't be lazy and just type it out so it works on any platform. =/ Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569484 Share on other sites More sharing options...
freephoneid Posted June 19, 2008 Author Share Posted June 19, 2008 test.php ======= <?php include("lang/default/macro.php"); ?> <html> <head> <title><?=title?></title> </head> <body>Hello World</body> </html> macro.php ======== <?php define("title","I'm great"); ?> Now, when I run test.php, it does not display the title tag?????? Any help would really be appreciated!!! Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569489 Share on other sites More sharing options...
freephoneid Posted June 19, 2008 Author Share Posted June 19, 2008 Hi hitman6003, How to enable short tags? Thanks!! Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569492 Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 Don't enable short tags. Just do it the other way.....I don't see the big deal. Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569497 Share on other sites More sharing options...
Jabop Posted June 19, 2008 Share Posted June 19, 2008 There's nothing wrong w/ short tags if you're not trying to make your code portable. Short tags ftw Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569499 Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 It promotes sloppier coding instead of just doing it normally. And why wouldn't you code for portability? What if you had to switch servers and your new host didn't support short tags? Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569502 Share on other sites More sharing options...
Jabop Posted June 19, 2008 Share Posted June 19, 2008 It promotes sloppier coding instead of just doing it normally. And why wouldn't you code for portability? What if you had to switch servers and your new host didn't support short tags? I'd never use a shared hosting solution. I wouldn't host somewhere that didn't give me full access to the box that I'm paying for. Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569504 Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 It promotes sloppier coding instead of just doing it normally. And why wouldn't you code for portability? What if you had to switch servers and your new host didn't support short tags? I'd never use a shared hosting solution. I wouldn't host somewhere that didn't give me full access to the box that I'm paying for. Not you, necessarily. And based on the posts I've read on this forum, tons of "PHP coders" (lol, barely) try to find free hosts and garbage like that. So that's why you should always code for portability. =/ Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569508 Share on other sites More sharing options...
PFMaBiSmAd Posted June 19, 2008 Share Posted June 19, 2008 Short open tags are already turned off by default in php.ini recommended settings. This is the first step in depreciating and then removing a feature. Anyone using a setting against php.net recommendations is operating at his own risk of needing to go back and change his code should the setting be removed. I for one like to write code once and release it knowing that I won't have to revisit it just because I used a feature that won't be parsed on some servers when it can be written so that it will always be parsed by simply typing a few characters a handful of times in any file. Go a head and use short open tags if you don't have any aspirations to become a coder that will distribute or sale his code to others, where the person receiving the code might not have the ability to turn on short open tags. Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569520 Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 Yup, precisely. By the way: Zend's thoughts on it. Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569523 Share on other sites More sharing options...
Jabop Posted June 19, 2008 Share Posted June 19, 2008 Short tags are enabled my default. Not sure where you got that information from. Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569526 Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 Firstly, they're off by default in PHP6, which will open up any time now: ; - short_open_tag = Off [Portability] ; Using short tags is discouraged when developing code meant for redistribution ; since short tags may not be supported on the target server. ; NOTE: Using short tags should be avoided when developing applications or ; servers which are not under your control, because short tags may not ; be sure not to use short tags. short_open_tag = Off Secondly, PHP5 has this in its PHP.ini: ; NOTE: Using short tags should be avoided when developing applications or ; servers which are not under your control, because short tags may not ; be sure not to use short tags. Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569534 Share on other sites More sharing options...
Jabop Posted June 19, 2008 Share Posted June 19, 2008 I wonder why every single installation of php5 I've done has always have short tags enabled. Strange. Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569535 Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 They are, they just aren't recommended. In the php.ini-default (I think it's named that), they may be on, but in php.ini-recommended, I think they're off. Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569539 Share on other sites More sharing options...
Jabop Posted June 19, 2008 Share Posted June 19, 2008 So why did you guys say and point out that the short tags are disabled by default, if you just said they ARE enabled. Also, if they're so badly recommended, why would they be enabled by default. Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569540 Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 Because too many scripts currently rely on them. They're slowly removing them though, because they aren't on by default in PHP6. Guidelines also say to not use short tags because they aren't good coding practice. Read the link I showed you. Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569550 Share on other sites More sharing options...
PFMaBiSmAd Posted June 19, 2008 Share Posted June 19, 2008 You will note in my post that I clearly stated that the recommend setting is off and the exact php.net statement of why has already been quoted. Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569555 Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 Indeed. There's probably been tons of debates on this already, but it always ends up with the fact that short tags generally represent poor adhesion to PHP coding standards. Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569560 Share on other sites More sharing options...
Jabop Posted June 19, 2008 Share Posted June 19, 2008 Firstly, they're off by default in PHP6, which will open up any time now I just downloaded php6 to see if that was the case. Snapshot php6.0-200806191830.tar.bz2 php.ini-dist ; Allow the <? tag. Otherwise, only <?php and <script> tags are recognized. ; NOTE: Using short tags should be avoided when developing applications or ; libraries that are meant for redistribution, or deployment on PHP ; servers which are not under your control, because short tags may not ; be supported on the target server. For portable, redistributable code, ; be sure not to use short tags. short_open_tag = On Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569569 Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 Look in the php.ini-recommended file. [email protected]:/usr/local/php6/lib$ cat php.ini-recommended | grep 'short' ; - short_open_tag = Off [Portability] ; Using short tags is discouraged when developing code meant for redistribution ; since short tags may not be supported on the target server. ; NOTE: Using short tags should be avoided when developing applications or ; servers which are not under your control, because short tags may not ; be sure not to use short tags. short_open_tag = Off ^D Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569570 Share on other sites More sharing options...
Jabop Posted June 19, 2008 Share Posted June 19, 2008 Okay, which php.ini is used with the php6 installation? Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569573 Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 I believe it is generally advised to rename php.ini-recommended to php.ini and use that one. That's a given in MOST programs, actually. Some program installations these days have "recommended" configuration files. Link to comment https://forums.phpfreaks.com/topic/110989-define-function-not-working/#findComment-569576 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.