Posts by dtbaker

2821 posts
  • Australia
  • Community Moderator
  • Elite Author
  • Author had a Free File of the Month
  • Most Wanted Bounty Winner
  • Author had a File in an Envato Bundle
  • Has been a member for 5-6 years
  • Contributed a Blog Post
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+10 more
dtbaker Volunteer moderator says
A pet peeve of mine is when people continue to use the simple mysql_query for large projects. There are much better alternatives. :)

fork(); http://codecanyon.net/forums/thread/php-database-abstraction-layer-advantages-disadvantages/29179

2821 posts
  • Australia
  • Community Moderator
  • Elite Author
  • Author had a Free File of the Month
  • Most Wanted Bounty Winner
  • Author had a File in an Envato Bundle
  • Has been a member for 5-6 years
  • Contributed a Blog Post
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+10 more
dtbaker Volunteer moderator says

Have a read of this little post against db abstraction: http://jeremy.zawodny.com/blog/archives/002194.html

My question to other coders out there, how do you tackle database connections and queries in large php applications?

  • Is your code full of mysql_query(“SELECT * FROM ….”); snippets?
  • Do you have your own home-brew database class/functions/abstraction layer?
  • Do you use one of the popular PHP database abstraction layers out there?
2821 posts
  • Australia
  • Community Moderator
  • Elite Author
  • Author had a Free File of the Month
  • Most Wanted Bounty Winner
  • Author had a File in an Envato Bundle
  • Has been a member for 5-6 years
  • Contributed a Blog Post
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+10 more
dtbaker Volunteer moderator says

Downloading Aptana 3 now. Got a little project to work on tomorrow, might give myself a day in Aptana to test it out (haven’t heard of it before).

edit: oh dear.. eclipse .. projects… arrghh… * confused * i just want to open a folder and start coding

2821 posts
  • Australia
  • Community Moderator
  • Elite Author
  • Author had a Free File of the Month
  • Most Wanted Bounty Winner
  • Author had a File in an Envato Bundle
  • Has been a member for 5-6 years
  • Contributed a Blog Post
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+10 more
dtbaker Volunteer moderator says

What’s your favourite PHP IDE ?

Zend Studio 5.5

By far the fastest and feature rich IDE released. I can code PHP a million miles an hour using this beast. Unfortunately Zend dropped this for an eclipse based IDE in version 6 (huge mistake). But I still keep 5.5 around for the quick bit of coding.

Anything eclipse based

Yuk! * delete *

vim/emacs/notepad fans

Install PhpStorm (below)! You’ll pump out higher quality code faster. :)

PhpStorm

This is new on the block, and I’ve been using for about 5 months now. This is by far my new favourite. It does lack a few features that Zend 5.5 has, but is under heavy development and they really do listen to their forum users requests. The company behind this has been building IDE ’s for years, very good.

Some of the features I like in an IDE :

(at the moment PhpStorm ticks almost all of these):
  • Been able to Ctrl+click on a variable, method or function. The IDE will open the file where that was declared and take you to the line number so you can edit it.
  • Been able to Ctrl+click on pretty much everything else (eg: css class, css id, javascript function) and the IDE will take you to where that was defined so you can edit it.
  • Refactoring: rename a php variable/php method/php function/javascript function/css class/html id/ once and it will update every relevant usage of that element to the new one.
  • AutoCompletion: the IDE will give you a list of valid things you can type (eg: functions/methods) once you start typing. PhpStorm can autocomplete crap loads, javascript functions, json elements, jquery, jquery plugins (yup! it reads jquery plugins and gives you valid method()’s you can apply to a jquery object), css classes, html attributes, everything!! and if it doesn’t find something (eg: $myClass->method(); ) you can click it and it will go and make it for you. Makes extreme programming fast.
  • Find replace in path: an easy way to find/replace text or regex in a list of files.
  • Code formatting: if you have a mixed HTML /PHP/JS file there should be a button that indents all the code in a standard way.
  • Block commenting: an easy one, select some text, Ctrl+/ should comment that block out (in the selected text’s native programming language )
  • Content duplication: pressing Ctrl+d on a line will copy that line to the one below. (same concept for selected block of text). This doesn’t interfere with the copy/paste buffer and makes coding so much easier.
  • Word wrap: nice to have. surprising number of java based IDE ’s don’t have this.
  • FTP integration: dislike having to open a separate program to upload files. The IDE should have some basic upload method.
  • Version control integration: Ability to easily interact with your favourite version control. Should have all the mod cons including diff and the ability to see a files version history.

So, what’s your fav IDE and why?

2821 posts
  • Australia
  • Community Moderator
  • Elite Author
  • Author had a Free File of the Month
  • Most Wanted Bounty Winner
  • Author had a File in an Envato Bundle
  • Has been a member for 5-6 years
  • Contributed a Blog Post
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+10 more
dtbaker Volunteer moderator says

Passing / modifying superglobals incorrectly

My fav, I got into a fight over this one and caused some jobs to be lost

Passing super globals (like $_POST, $_GET, $_REQUEST) into a function, without adjusting the superglobal variable name. Similar code was in every function in the entire huge crappy app.

some_function($_POST);
function some_function($_POST){
    $_POST['foo'] = 123;
} 

This is wrong on so many levels. Like, urgh, re-declaring $_POST in the local function scope. Like. argghh. anywho.

2821 posts
  • Australia
  • Community Moderator
  • Elite Author
  • Author had a Free File of the Month
  • Most Wanted Bounty Winner
  • Author had a File in an Envato Bundle
  • Has been a member for 5-6 years
  • Contributed a Blog Post
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+10 more
dtbaker Volunteer moderator says

try to use the correct HTML markup tags instead of span with a class

reason: cross browser nightmare ! and try not to name classes the same as HTML tags. confusing!

Original html code

<span class="h2">Some Text</span>

New html code

<h2>Some Text</h2>

(apply your css styles to “h2” instead of ”.h2”)

2821 posts
  • Australia
  • Community Moderator
  • Elite Author
  • Author had a Free File of the Month
  • Most Wanted Bounty Winner
  • Author had a File in an Envato Bundle
  • Has been a member for 5-6 years
  • Contributed a Blog Post
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+10 more
dtbaker Volunteer moderator says

Limit using ‘print’ or ‘echo’ to spit out large blocks of HTML code:

reason: when your IDE has some nice HTML features, it cannot apply these to php strings.

for example, in the below string there is a html error (an additional ” in the view link) which is not picked up by the IDE until we take this html out of a php string:

Original PHP

print '
    <td>
        '. $row['sent_dt'] .'
    </td>
    <td>
        '. $row['subject'] .'
    </td>
    <td>
        '. $row['to'] .'
    </td>
    <td align="center">
        <a href="composeemail.php?email_id='.$row['email_id'].'"">View
    </td>';

New PHP

?>
    <td>
        <?php echo $row['sent_dt'];?>
    </td>
    <td>
        <?php echo $row['subject'];?>
    </td>
    <td>
        <?php echo $row['to'];?>
    </td>
    <td align="center">
        <a href="composeemail.php?email_id=<?php echo $row['email_id'];?>">View</a>
    </td>

2821 posts
  • Australia
  • Community Moderator
  • Elite Author
  • Author had a Free File of the Month
  • Most Wanted Bounty Winner
  • Author had a File in an Envato Bundle
  • Has been a member for 5-6 years
  • Contributed a Blog Post
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+10 more
dtbaker Volunteer moderator says

Accidental assignment within if statement:

This happens all to often, I just found one today in some code I’m fixing.

The error looks like this:

if($_REQUEST['action'] = 'delete'){  // run the delete code...

Of course, delete will run every time. This should be:

if($_REQUEST['action'] == 'delete'){  // run the delete code..

An even better practice to get into is swapping the variables around:

if('delete' == $_REQUEST['action']){  // run the delete code..

This way if you do accidentally use = instead of == you will get a PHP error.
It’s a hard practice to get into, but well worth it in the long run.

2821 posts
  • Australia
  • Community Moderator
  • Elite Author
  • Author had a Free File of the Month
  • Most Wanted Bounty Winner
  • Author had a File in an Envato Bundle
  • Has been a member for 5-6 years
  • Contributed a Blog Post
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+10 more
dtbaker Volunteer moderator says

Limit the use of unnecessary HTML markup code:

reason: harder to get it working cross browser. 
like below, you could style “td” tags just the same as a the “h2” span is.

Original code: (this span was in EVERY td and th in the entire application)

print '<td><span class="h2">'. $row['rcvd_dt'] .'</span></td>';

New Code:

print '<td>'. $row['rcvd_dt'] .'</td>';
2821 posts
  • Australia
  • Community Moderator
  • Elite Author
  • Author had a Free File of the Month
  • Most Wanted Bounty Winner
  • Author had a File in an Envato Bundle
  • Has been a member for 5-6 years
  • Contributed a Blog Post
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+10 more
dtbaker Volunteer moderator says

Thought I’d start a thread about some annoying/bad PHP programming code. The large PHP projects I get handed (which were started by cheap out-sourcing or self-taught programmers) tend to include these or similar over and over again.

Don’t hardcode colours into php files (or even html files for that matter)

use css classes instead, so you only have to update a single css rule instead of every single php file in the whole app.

Original code:

 if ($oddRow == 1) {
         print '<'.'tr style="background-color: white;">';
         $oddRow = 0;
      }else{
         print '<'.'tr style="background-color: #dddddd;">';
         $oddRow = 1;
      }

Replacement PHP code:

 print '<'.'tr class=" . (($oddRow++%2) ? 'even' : 'odd') . ">';

New CSS code:

tr.odd{background:#FFF;} tr.even{background:#DDD;}

Feel free to post your own bad code below!

by
by
by
by
by
by