Outdated PHP delimiters

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
maxd
Forum Commoner
Posts: 41
Joined: Sun Dec 04, 2005 12:12 am
Location: Denver

Outdated PHP delimiters

Post by maxd »

Hello, all.

A quick question about PHP delimiters. A client is prepping to migrate their site from one server to another, and it just occurred to me that I've noticed a lot of PHP code with only the <? delimiter, ie:

Code: Select all

<? 
//code 
?>
Rather than:

Code: Select all

<?php
// code
?>
It seems to me that model doesn't work on PHP 5 installs, which I imagine the new server will have.

Am I right about that?

Thanks,
max
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If the PHP 5 install has short_open_tag on, they will work. However I would suggest fixing the code over turning the setting on.
Xoligy
Forum Commoner
Posts: 53
Joined: Sun Mar 04, 2007 5:35 am

Post by Xoligy »

A simple regexp file search and replace should do it. If you have a good IDE you should be able to do it from there.
maxd
Forum Commoner
Posts: 41
Joined: Sun Dec 04, 2005 12:12 am
Location: Denver

Thanks

Post by maxd »

I was thinking I could perform a global find and replace with BBEdit (my editor of choice). This is a massive site, and my initial search found nearly 3000 instances of the code in question. So, definitely something I want to tackle BEFORE deployment to the new server, so I can do a local search.

Are there any other code issues I should search for to make sure the site will function on newer versions of PHP?

I appreciate any tips.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

register globals, session problems, classes using "var," magic quote conflicts are a few that come to mind.
maxd
Forum Commoner
Posts: 41
Joined: Sun Dec 04, 2005 12:12 am
Location: Denver

Post by maxd »

Thanks, feyd.

I'll poke around and see if there's a hint of any of those in play. As I said, the site is over 1,000 pages. They really only used PHP for includes and the like (hence, the enormous size), so I'm hoping we'll be OK.
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

You can also turn on any settings you need in .htaccess instead of wasting your time on editing 1000+ files.
mentor
Forum Contributor
Posts: 100
Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan

Post by mentor »

stereofrog wrote:You can also turn on any settings you need in .htaccess instead of wasting your time on editing 1000+ files.
This is a better option.


Here is the list of all php.ini directives
http://www.php.net/manual/en/ini.php

To allow short php delimeters simply create a file named ".htaccess" and put the below code to change settings

php_value short_open_tag 1
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Dudes, that is totally the wrong approach. feyd already mentioned it, and I will reiterate it, do not make your PHP5 installation that same insecure, outdated crap that a PHP3 install would be. Would you turn on register_globals just so your code will work, or will you make your code better so it will work on a more secure setup?

Leave short tags off. Leave register_globals off. If this is a production system, turn off display_errors and display_startup_errors. You might also want to lower your error_reporting from E_ALL (or E_STRICT in PHP5) to E_ALL ~ E_NOTICE to prevent unwanted notice level reports form spashing to the screen. If you are talking to a Sybase or MSSQL server database, raise your database error severity levels to 16 from the default 11 to prevent changing context notices.

Then, after checking into the things feyd has stated, make sure you check your code for objects that are passed by reference, as PHP5 does not like that much. Also, make sure the appropriate extensions are loaded on the new server so that any extension used on the old server are maintained (so your code doesn't break because of an extension issue).
Post Reply