The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
PHP5 - Where does all the evil code come from?
Discuss Where does all the evil code come from? in the PHP Development forum on Dev Shed. Where does all the evil code come from? PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 21st, 2012, 06:05 PM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
|
PHP5 - Where does all the evil code come from?
Hi,
even though I'm still quite new in this forum, I've noticed that certain bad code patterns keep popping up. I'm talking about stuff like
PHP Code:
$query = mysql_query('SELECT * FROM users') or die(mysql_error());
or document.write() or ancient HTML markup.
It happens so often that you almost have to begin every reply with a long preamble of why this and that is bad and what you should use instead.
I wonder where this code comes from and why it doesn't die out. For example, the MySQLi extension is more than 8 years old. Yet still nobody seems to know it, and instead the 12 year old(!) mysql_ functions keep being used. Do books spread this stuff? Or is it the bad tutorials?
I mean, 12 years ... That's when the Internet Explorer 5 came out, and nobody uses that any longer.
|

December 21st, 2012, 06:33 PM
|
 |
JavaScript is not spelt java
|
|
Join Date: Feb 2011
Location: Landan, England
|
|
It is quite rare to see mysql i on forums. I suppose people starting out associate PHP and MySql and think mysqli must be something more advanced  . I suppose, also, there must be so much legacy code out there that is never updated. (It is largely a question of just replacing mysql with mysqli. Although, migrating to the object-version or PDO would be preferable.)
We constantly see ancient JS code (language="JavaScript1.6"!!) as well. I suppose most JS tutorial-sites were written many years ago and never updated; and, generally, their pages don't show a date.
My personal bug-bear (although off-topic - sorry!) is the use of form, button, image, etc.. as variable names (in JS and others). People show a distinct lack of imagination  . It makes their code very difficult to read and might bite them some time in the (near) future.
Last edited by AndrewSW : December 21st, 2012 at 06:39 PM.
|

December 21st, 2012, 06:57 PM
|
|
|
|
Google PHP MySQL Tutorial and see what the first few links pull up. You'll have your answer.
__________________
I ♥ ManiacDan & requinix
This is a sig, and not necessarily a comment on the OP:
Please don't be a help vampire!
|

December 21st, 2012, 07:11 PM
|
 |
JavaScript is not spelt java
|
|
Join Date: Feb 2011
Location: Landan, England
|
|
|
They should have named it MySql2, then the intent is obvious (I myself tend to forget that the i stands for 'improved').
|

December 21st, 2012, 11:16 PM
|
|
|
|
It is because there is so many tutorials out there using the old way of doing things and they still dominate the search engines.
|

December 22nd, 2012, 02:21 AM
|
 |
For POny!
|
|
Join Date: Apr 2012
Location: Amsterdam
|
|
Quote: | Originally Posted by drumn4life0789 It is because there is so many tutorials out there using the old way of doing things and they still dominate the search engines. |
That probably is it.
|

December 24th, 2012, 11:26 AM
|
 |
Contributing User
|
|
Join Date: Nov 2012
Location: Oxford, United Kingdom
Posts: 40

Time spent in forums: 1 Day 2 h 18 m 23 sec
Reputation Power: 1
|
|
|
Well I think people just use mysql_* because they think it's easier. And tbh, it looks it too. At least, from a beginners view.
I think it's also down to OOP. Most beginners are not just beginners to PHP, but beginners to programming in general. So they see the OOP approach and they think 'WTF'. I know I did it when I first started.
Although PDO and MySQLi is beginning to over take mysql_* in most search results, there are still high ranked sites advising people to use the old mysql_* ways - such as w3schools.
But give it some time and keep advising people to use PDO/MySQLi, and hopefully, this mysql_* rubbish will be at an end.
Well actually, mysql_* has now been depreciated in the latest version of PHP. So when hosts start updating their PHP versions, we should see some better results.
|

December 26th, 2012, 06:37 PM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
|
You're probably right about the bad tutorials. I'm still baffled by how much influence they have. It's like every single newbie reads the same bad tutorial, because they all use "mysql_query() or die(mysql_error())".
It's so sad. I'm waiting for a PHP version that will finally remove the old baggage and force people to update their sh*t. Or will we have to same discussion in 10 years?
I'm not sure, but this seems to be a PHP issue. In Ruby, for example, you do have people still using the old (and now deprecated) version, but you won't find code somebody has dug out of an 90s tutorial like it's the case with PHP.
|

December 26th, 2012, 06:57 PM
|
 |
Contributing User
|
|
Join Date: Dec 2012
Location: Chicago
Posts: 49
Time spent in forums: 17 h 27 m 23 sec
Reputation Power: 1
|
|
|
As I was forcefully reminded earlier today: Its deprecated not depreciated.
|

December 27th, 2012, 01:51 AM
|
|
Contributing User
|
|
Join Date: Dec 2012
Location: Ithaca
Posts: 64
Time spent in forums: 13 h 4 m 57 sec
Reputation Power: 1
|
|
|
Well MySQLi is in somewhat of an awkward situation. The advanced programmers tend to use more powerful and flexible PDO, while beginner coders just stick to mysql basic functions since they dont know OOP. Where does MySQLi fit in the picture? Sure some people use it for preference, but its really isnt that special.
Id say the reason why some people stick to mysql_query() or die() is that this has been the way they were taught PHP. For procedural programmers, thats probably sufficient for their web development. Sure it has issues, but in many circumstances a beginner coder only realize the severeness of the issue once they are hit hard. Its difficult to change the old habit once it grows on you. PHP is easy to learn and use, but on the other hand it does not promote good application design.
|

December 27th, 2012, 07:11 AM
|
 |
Contributing User
|
|
Join Date: Dec 2012
Location: Chicago
Posts: 49
Time spent in forums: 17 h 27 m 23 sec
Reputation Power: 1
|
|
I am a 66 year old programmer/DBA/network engineer/retired person. I have been coding a LAMP application as a hobby for about 2 years. [Wow! No schedules! No time pressure!  [ Ahem, back to the topic Rich.]] I started out using the old MYSQL API. [I was totally unaware that it was deprecated.]
Earlier this year I found out. I immediately stopped working on the project, did a survey of the two alternatives and gave my self a brief crash course on mysquli, my choice over PDO. I am currently recoding all database access to take advantage of this new API.
My point is that some of the users of the old API are probabily doing it out of ignorance. Putting a brief note about mysquli and PDO in all those out of date examples could work wonders!
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|