- Should I upgrade to PHP5 now, and why?
- How many servers supported it, and which?
- Can I install PHP4 with PHP5 on same system?
| SitePoint Sponsor |
- Should I upgrade to PHP5 now, and why?
- How many servers supported it, and which?
- Can I install PHP4 with PHP5 on same system?
- Probably. PHP5 has been out for 2 and a half years now, and there's no excuse to justify why peopl ehaven't moved to it, yet, except perhaps the laziness of hosts.
- I don't know how many, nor which ones. Do you really expect a list here? There seem to be more and more hosting providers supporting PHP5.
- Yes, but not both as an apache module. One of them must be installed as a CGI
Can you explain more about running PHP4 and PHP5 in same time ?

I have recently installed a YouTube clone script, that do not work well on PHP5 (some problems like the title of movie do not change, tags showing duplicate). At last i have to install php4 on the server to get the script working. I think it will create problem with some scripts. If you have lot of PHP sites, you should make sure it works on PHP5.
PHP 5 x10 Slower Than PHP 4:
http://www.apachelounge.com/forum/vi...&postorder=asc


PHP 5 is not inherently 10x slower than PHP 4. That's some configuration issue specific to that one person's setup. If there was any significant performance difference I would've noticed it when I upgraded the server W3Counter runs on from PHP4 to PHP5 a few months ago. It handles hundreds of Apache requests per second (each needing the PHP interpreter) and the load averages 4-6 throughout the day. If PHP5 had some inherent performance issues it would've gone up.
Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
Also, if you want better OO support you certainly must switch to PHP 5.
PHP 4 is not an old way !
Source:PHP 5 is currently only being used in about 4% of the PHP hosts, against about 95% that still use PHP 4.
Manuel Lemos
http://www.phpclasses.org/browse/package/2572.html





I'm still on PHP, and until that 4% grows to like 40% I'll stick with 4.
I don't use objects so my scripts should function in both versions.


A two year old class description is hardly a good source for the PHP5 installed base percentage.
Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more

This very thing was hashed out in a post a while back. I still don't get the oo people. I have researched and researched this oo thing, and I do not care what you call it, if you have a database online, an html form for user input is still part of the overall thing. Why do they care so, so, so much about seperating presentation from database? No mater what you do, it still has to all work / integrate together. It's as though they are like those hal bob comet followers, like a cult. I may be wrong, but I just don't believe all these big companies have oop behind their code. I believe a lot still use a regular common sense approach. Just an obervation.





I prefer functions over objects.
But for some larger projects objects make it easier to customize things and write plugins.
For most things in PHP though, I really don't see a point in OO.

I totally agree with using functions. From what I've seen, all oop is like one giganic function anyway. To me having a few well written smaller functions are very efficient. I even totally agree with using include files for things like a connection that will be used over and over again.


Go into software development as a profession (maintaining Cobol code from the 70s doesn't count) and you'll start thinking otherwise.
Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
I'm with Dan here. I manage a team of developers, we had to do work on an existing code base for a client who had a hobbiest developer do the work. The previous dev didn't separate the presentation and functional logic of his code which resulted in more than $10,000 of additional work just picking everything apart.
While to you as the one who originally wrote the code it might make sense to just leave the two integrated. Try seeing how quickly you can work with a code base that's entirely interwoven that you didn't write compared to one that has a great deal of neatly packaged separated components.
As a project manager, I dread hearing the words "existing code base" unless I know its all been developed with portability in mind. :P
Sean "Takai" Saulnier
New project coming soon

I am sorry you do not have any confidence in your programming skills. Me, if I program something, It will be good to go and last a long time. Why do you have to maintain code you write so much. Futhermore, are you saying that if you have some mixed php and html (where you escape html while looping to display a table), on the same page, you're saying it's hard to add one more field to display? An example, if customer decides to have a field added to the database that originally wasn't there. A little secret to readers out there, this field can be added quicker in a mixed php/html page than a monster oop thing. And futhermore, you have to add it in the oop and in the presentation layers. So there is no earthly way it's easier to maintain anything in oop. In fact it's much harder to maintain that oop style code. I'm at work now, but when I get home I am going to paste an example.


Because business requirements change and grow over the years. Most large companies don't have software developed once then never change it again. They constantly evolve it to meet their new needs.
That's why OOP as a methodology is even more important than OOP as a design decision. Multiple people will work on the same application, both together and at different times, and often are coming in at a later time without being part of writing the original program. OO code is inherently self-documenting, the components are loosely coupled so changes in one component don't often change other components, they are encapsulated so that changes within a class method that don't change the interface to that class don't impact code that uses that class... these things reduce the time and risk involved in evolving software over time and working on software in a team environment.
In contrast, procedural coding almost requires code duplication and creates tight coupling between the different layers of the application. The potential for bugs to be introduced when someone has to change the program goes up exponentially. Someone that wasn't part of writing the program can't always tell where and in how many places they'll have to make a change to do so globally throughout a program, or what side effects the change will have on other code since there's no defined interface between what they're changing and everything else.
Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more





There may be another issue one may consider. There are open source codes that are still in php4. If you are going to code everything (which may be a bit far from reality) by yourself and are sure not to use any opensource stuffs, you may go to php5.
Personally I have kept both php4 and 5 in my server (5 running as CGI), but using php4 primarily as I am using open source things now and then, and I guess not all of them are yet offering a 4 and 5 versions (a lot are still in 4). And then, I am not doing OOP coding yet, the old style coding works pretty fine for me.





Agree, this is also the last thing I wish to hear from a client. Past experiences has taught me that when client tells "everything is done, all what I need a few modifications" is some thing like "be prepared for weeks of sleepless nights".
I often prefer building from scratch, unless the previous coder had a good sound logic.

Below is an image of a tableview, and some code:
http://jimdiane.byethost9.com/table.jpg
Lets zero in on just this portion:Code:<html> <head> <title>Implementing Paging With More Than One Column</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <!--<LINK href="include/style.css" type=text/css rel=stylesheet>--> <meta name="keywords" content="freeze HTML table columns; lock columns; freeze columns; CSS column locking; prevent column scroll; fixed column; fixed table header; lock header; freeze header"> <link rel="stylesheet" href="include/locked-column.css" type="text/css"> <script type="text/javascript"> function lockCol(tblID) { var table = document.getElementById(tblID); var cTR = table.getElementsByTagName("TR"); //collection of rows if (table.rows[0].cells[0].className == '') { for (i = 0; i < cTR.length; i++) { var tr = cTR.item(i); tr.cells[0].className = 'locked' tr.cells[1].className = 'locked' } document.getElementById('toggle').innerText = "Unlock First Column"; } else { for (i = 0; i < cTR.length; i++) { var tr = cTR.item(i); tr.cells[0].className = '' } document.getElementById('toggle').innerText = "Lock First Column"; } } </script> </head> <body onload="lockCol('tbl')"> <?php include 'library/config.php'; include 'library/opendb.php'; set_magic_quotes_runtime(0); if (isset($_POST['t1'])) { $t1 = $_POST['t1']; } else { $t1 = $_GET['t1']; } // how many rows to show per page $rowsPerPage = 5; // by default we show first page $pageNum = 1; // if $_GET['page'] defined, use it as page number if(isset($_GET['page'])) { $pageNum = $_GET['page']; $page = $_GET['page']; } else { $pageNum = 1; $page = 1; } $offset = ($pageNum - 1) * $rowsPerPage; $query = "SELECT petid, petname, species, sex, ownerid, petowner, ostreet, dogpic"; $query = $query . " FROM pets"; $query = $query . " WHERE petname Like '".addslashes("$t1%")."'"; $query = $query . " ORDER BY petname asc "; $pagingQuery = "LIMIT $offset, $rowsPerPage"; $result = mysql_query($query . $pagingQuery) or die('Error, query failed'); echo "<div id=tbl-container>"; echo "<table border=1 id=tbl style=behavior:url(move-lock-col.htc)>"; echo "<thead>"; echo "<tr>"; echo "<th>PET ID</th>"; echo "<th>PET NAME</th>"; echo "<th>SPECIES</th>"; echo "<th>SEX</th>"; echo "<th>OWNER ID</th>"; echo "<th>PET OWNER</th>"; echo "<th>STREET</th>"; echo "<th>PIC</th>"; echo "<th>EDIT</th>"; echo "<th>VIEW</th>"; echo "</tr>"; echo "</thead>"; echo "<tbody>"; while($row=mysql_fetch_array($result)) { $tmppetid = $row['petid']; echo "<tr onMouseover=this.bgColor='lightgrey' onMouseout=this.bgColor='#FFFFFF'>"; echo "<td>$row[0]</td>"; echo "<td onClick=\"location.href='edit2.php?petid=$tmppetid&page=$page&t1=$t1'\">$row[1]</td>"; if (empty($row[2])) { echo "<td> </td>"; } else { echo "<td>$row[2]</td>"; } if (empty($row[3])) { echo "<td> </td>"; } else { echo "<td>$row[3]</td>"; } if (empty($row[4])) { echo "<td> </td>"; } else { echo "<td>$row[4]</td>"; } if (empty($row[5])) { echo "<td> </td>"; } else { echo "<td>$row[5]</td>"; } if (empty($row[6])) { echo "<td> </td>"; } else { echo "<td>$row[6]</td>"; } if (empty($row[7])) { echo "<td> </td>"; } else { $tpic = $row[7]; echo "<td><a href=\"upload/$tpic\" target=\"_blank\">$tpic</a></td>"; } // $tmppetid = $row['petid']; echo "<td><a href=\"edit2.php?petid=$tmppetid&page=$page&t1=$t1\"> EDIT </a></td>"; echo "<td><a href=\"view2.php?petid=$tmppetid&page=$page&t1=$t1\"> VIEW </a></td>"; } echo "</tr>"; echo "</tbody>"; echo "</table>"; echo "</div>"; echo "<br>"; $result = mysql_query($query) or die('Error, query failed'); $numrows = mysql_num_rows($result); // how many pages we have when using paging? $maxPage = ceil($numrows/$rowsPerPage); $self = $_SERVER['PHP_SELF']; // creating 'previous' and 'next' link // plus 'first page' and 'last page' link // print 'previous' link only if we're not // on page one if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page&t1=$t1\">[Prev]</a> "; $first = " <a href=\"$self?page=1&t1=$t1\">[First Page]</a> "; } else { $prev = ' [Prev] '; // we're on page one, don't enable 'previous' link $first = ' [First Page] '; // nor 'first page' link } // print 'next' link only if we're not // on the last page if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page&t1=$t1\">[Next]</a> "; $last = " <a href=\"$self?page=$maxPage&t1=$t1\">[Last Page]</a> "; } else { $next = ' [Next] '; // we're on the last page, don't enable 'next' link $last = ' [Last Page] '; // nor 'last page' link } // print the page navigation link echo $first . $prev . " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " . $next . $last; include 'library/closedb.php'; ?> <P>CLICK<a href="menu.html"> HERE </a>TO GO BACK</td></P> </body> </html>
Ok, this should be the only part of the code that would change. If the customer wants a field added, (say date of birth), then anyone who has been around php for six months could add a field to this fragment of php code. So where is the "hard part"? AS you say why couldn't a team member add to this another field?Code:echo "<th>PET ID</th>"; echo "<th>PET NAME</th>"; echo "<th>SPECIES</th>"; echo "<th>SEX</th>"; echo "<th>OWNER ID</th>"; echo "<th>PET OWNER</th>"; echo "<th>STREET</th>"; echo "<th>PIC</th>"; echo "<th>EDIT</th>"; echo "<th>VIEW</th>"; echo "</tr>"; echo "</thead>"; echo "<tbody>"; while($row=mysql_fetch_array($result)) { $tmppetid = $row['petid']; echo "<tr onMouseover=this.bgColor='lightgrey' onMouseout=this.bgColor='#FFFFFF'>"; echo "<td>$row[0]</td>"; echo "<td onClick=\"location.href='edit2.php?petid=$tmppetid&page=$page&t1=$t1'\">$row[1]</td>"; if (empty($row[2])) { echo "<td> </td>"; } else { echo "<td>$row[2]</td>"; } if (empty($row[3])) { echo "<td> </td>"; } else { echo "<td>$row[3]</td>"; } if (empty($row[4])) { echo "<td> </td>"; } else { echo "<td>$row[4]</td>"; } if (empty($row[5])) { echo "<td> </td>"; } else { echo "<td>$row[5]</td>"; } if (empty($row[6])) { echo "<td> </td>"; } else { echo "<td>$row[6]</td>"; } if (empty($row[7])) { echo "<td> </td>"; } else { $tpic = $row[7]; echo "<td><a href=\"upload/$tpic\" target=\"_blank\">$tpic</a></td>"; }
As far as evolving, I wish people would leave things alone for at least a few years. I hope it wasn't one of you opper's that messed up my yahoo tv guide. It was wonderful before, now it's stupid. In fact it takes more mouse clicks and page views to see if a show is a repeat. PEOPLE, quit messing with things that ain't broke. I have nothing against people having kids, but boy I think there are too many people out there now with nothing to do, so they come up with stupid stuff. I still have nothing against the way things were when dbase 3+ reined. Modern programmers, stop messing up the web, and programming.
By the way, show me one fully functional site that can do something in oop. I mean complex, not a flat file type table. Just one complex business type site that does things like a lookup to fill in customer information on an invoice.
Last edited by jim9; Jan 16, 2007 at 17:44. Reason: image too big
Honestly though, I saw the other thread where jim9 provoked debate on the exact same issue, and I think we're beating a dead horse here by rehashing all the same arguments.
It comes down to, if you want to take advantage of the new features offered in PHP5, then you should upgrade. if you think it's important to stay up-to-date with new software versions, then you should upgrade.

As stated by alMubarmij, if the newer php5 is so good how come a only small percentage of host offer it? I will answer this, you shouldn't have to make program changes from one version to another. Ok, I would understand if it were the year 2020 and php 50 is out. Then you should look into some changes in your code. People in general like backwards compatability. What if microsoft vista came out and suddenly no windows applications would work (web stuff included) that was windows based, without having to reprogram everything you've done in the past year. I bet most people would be mad. Instead, they make new operating systems "backward compatible" to a point. For example, something you programmed on a windows xp computer will work on vista.
In php5 however, there is code that won't work from php4. That's why. I tryed php5, and even liked it. But I also had trouble finding a large population of host. Of course a big company, like fedex, probably have in house servers, so it doesn't matter. But most smaller companies and individuals can't afford the time or money to self host.
Bookmarks