SlideShare uma empresa Scribd logo
1 de 48
Coding
Horrors
A Horror Film Fan’s Guide to
PHP Coding Nightmares
Coding
Horrors
Coding Horrors
Coding Horrors – Friday the 13th
Coding Horrors – Friday the 13th
// 3 month reports
$date_from = date("d-m-Y", strtotime(" -3 months"));
$date_to = date('d-m-Y');
$get = "select * from table1 where date between '$date_from' and '$date_to’”;
$get_connect = mysqli_query($con2, $get);
$get_rows = mysqli_num_rows($get_connect);
Coding Horrors
Coding Horrors – The Ring
Coding Horrors – The Ring
$studentArray = array();
$query1 = "SELECT * FROM students ORDER BY name";
$studentList = mysqli_query($conn,$query1)
or die ("cannot query the table1: " . mysqli_error($conn));
while ($student = mysqli_fetch_array($studentList)) {
$studentId = $student['id'];
$courses = array();
$query2 = "SELECT * FROM classes WHERE studentid='$studentId'";
$classList = mysqli_query($conn,$query2)
or die ("cannot query the table2: " . mysqli_error($conn));
while ($class = mysqli_fetch_array($classList)) {
array_push($classes, $class['name']);
}
array_push($studentArray, array($studentId, $student['name'], implode(', ', $classes)));
}
Coding Horrors – The Ring
SELECT s.id,
s.name,
group_concat(c.name separator ', ')
FROM students s
LEFT JOIN classes c
ON c.studentid = s.id
GROUP BY s.id,
s.name
ORDER BY s.name;
Coding Horrors
Coding Horrors – The Mummy
Coding Horrors – The Mummy
$Data = $connection->prepare(
"SELECT * FROM :TableName ORDER BY :OrderByColumn :OrderDirection LIMIT 10 OFFSET :Offset"
);
$Data->bindValue(':TableName', $TableName, PDO::PARAM_STR);
$Data->bindValue(':Offset', $Offset, PDO::PARAM_INT);
$Data->bindValue(':OrderByColumn', $OrderColumn, PDO::PARAM_STR);
$Data->bindValue(':OrderDirection', $OrderDirection, PDO::PARAM_STR);
$Data->execute();
Coding Horrors
Coding Horrors – Night of the
Living Dead
Coding Horrors – Night of the
Living Dead
function getAddressDetails() {
$data->name = 'Mark';
// $data->address = 'mi casa';
// $data->city = 'Manchester';
// $data->country = 'UK';
// return json_encode($data, JSON_UNESCAPED_UNICODE);
return json_encode($data);
}
Coding Horrors – Night of the
Living Dead
function addValues($a, $b, $options) {
$sum = 0;
return $a + $b;
}
Coding Horrors – Night of the
Living Dead
function squareIt($bar) {
return $bar ** 2;
$bar *= $bar;
return $bar;
}
Coding Horrors
Coding Horrors – The Ring (US
Remake)
Coding Horrors – The Ring (US
Remake)
DRY
Don’t Repeat Yourself
Coding Horrors
Coding Horrors – The Mummy
Returns
Coding Horrors – The Mummy
Returns
$q = "SELECT id, name FROM test WHERE name like '%:foo%'";
$s = "carrot";
$sth = $dbh->prepare($q);
$sth->bindParam(':foo', $s);
$sth->execute();
Coding Horrors – The Mummy
Returns
$q = "SELECT id, name FROM test WHERE name like :foo";
$s = "carrot";
$s = "%{$s}%";
$sth = $dbh->prepare($q);
$sth->bindParam(':foo', $s);
$sth->execute();
Coding Horrors – The Mummy
Returns
$q = "SELECT * FROM posts WHERE post_title LIKE :q OR post_text LIKE :q";
$s = "carrot";
$s = "%{$s}%";
$sth = $dbh->prepare($q);
$sth->bindParam(':q', $s);
$sth->execute();
Coding Horrors – The Mummy
Returns
$q = "SELECT * FROM posts WHERE post_title LIKE :q1 OR post_text LIKE :q2";
$s = "carrot";
$s = "%{$s}%";
$sth = $dbh->prepare($q);
$sth->bindParam(':q1', $s);
$sth->bindParam(':q2', $s);
$sth->execute();
Coding Horrors
Coding Horrors – Halloween
Coding Horrors – Halloween
function dates() {
$startDate = new DateTime();
$endDate = (clone $startDate)
->add(new DateInterval('P1Y'));
$dateRange = new DatePeriod($startDate, new DateInterval('P1M'), $endDate);
foreach($dateRange as $date) {
yield $date;
}
}
foreach(dates() as $date) {
echo $date->format("M Y") . PHP_EOL;
}
Coding Horrors – Halloween
Jan 2018
Feb 2018
Mar 2018
Apr 2018
May 2018
Jun 2018
Jul 2018
Aug 2018
Sep 2018
Oct 2018
Nov 2018
Dec 2018
Jan 2018
Mar 2018
Apr 2018
May 2018
Jun 2018
Jul 2018
Aug 2018
Sep 2018
Oct 2018
Nov 2018
Dec 2018
Jan 2019
Coding Horrors
Coding Horrors – Alien
Coding Horrors – Alien
if (strpos(" " . $fileURL, "s3://") >= 1) {
// Do something
}
Coding Horrors – Alien
Coding Horrors – Alien
if (strpos($fileURL, "s3://") !== false) {
// Do something
}
Coding Horrors
Coding Horrors – Se7en
Coding Horrors – Se7en
$calendar = [
01 => 'January',
02 => 'February',
03 => 'March',
04 => 'April',
05 => 'May',
06 => 'June',
07 => 'July',
08 => 'August',
09 => 'September',
10 => 'October',
11 => 'November',
12 => 'December',
];
Coding Horrors – Se7en
1 => January
2 => February
3 => March
4 => April
5 => May
6 => June
7 => July
0 => September
10 => October
11 => November
12 => December
Coding Horrors
Coding Horrors – Scream
Coding Horrors – Scream
$sql = "SELECT MAX(id) AS max_page FROM videos";
$result = @$conn->query($sql);
$row = @mysql_fetch_array($result);
echo $row["max_page"];
Coding Horrors
Coding Horrors – Dawn of the Dead
Coding Horrors – Dawn of the Dead
/**
* Convert a date from PHP to Excel
*
* @param mixed $dateValue unix timestamp or datetime object
* @param string $timezone Optional timezone name for adjustment from UTC
* @return mixed Excel date/time value
**/
public function PHPToExcel(DateTimeImmutable $dateValue, DateTimeZone $timezone = null) {
// Do stuff
}
Coding
Horrors
Coding
Horrors
Who am I?
Mark Baker
Design and Development Manager
InnovEd (Innovative Solutions for Education) Ltd
Coordinator and Developer of:
Open Source PHPOffice library
PHPExcel (PHPSpreadsheet), PHPWord, PHPPresentation (formerly PHPPowerPoint), PHPProject, PHPVisio
Minor contributor to PHP core
@Mark_Baker
https://github.com/MarkBaker
http://uk.linkedin.com/pub/mark-baker/b/572/171
http://markbakeruk.net

Mais conteúdo relacionado

Mais procurados

Crazy things done on PHP
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHPTaras Kalapun
 
20 modules i haven't yet talked about
20 modules i haven't yet talked about20 modules i haven't yet talked about
20 modules i haven't yet talked aboutTatsuhiko Miyagawa
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackVic Metcalfe
 
Random. Kinda.
Random. Kinda.Random. Kinda.
Random. Kinda.awwaiid
 
Anonymous classes
Anonymous classesAnonymous classes
Anonymous classesDarkmira
 
The Truth About Lambdas in PHP
The Truth About Lambdas in PHPThe Truth About Lambdas in PHP
The Truth About Lambdas in PHPSharon Levy
 
Gérer vos objets
Gérer vos objetsGérer vos objets
Gérer vos objetsThomas Gasc
 
20160227 Granma
20160227 Granma20160227 Granma
20160227 GranmaSharon Liu
 
Dip Your Toes in the Sea of Security (PHP MiNDS January Meetup 2016)
Dip Your Toes in the Sea of Security (PHP MiNDS January Meetup 2016)Dip Your Toes in the Sea of Security (PHP MiNDS January Meetup 2016)
Dip Your Toes in the Sea of Security (PHP MiNDS January Meetup 2016)James Titcumb
 
Communities - Perl edition (RioJS)
Communities - Perl edition (RioJS)Communities - Perl edition (RioJS)
Communities - Perl edition (RioJS)garux
 
循環参照のはなし
循環参照のはなし循環参照のはなし
循環参照のはなしMasahiro Honma
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regexbrian d foy
 
Perl Fitxers i Directoris
Perl Fitxers i DirectorisPerl Fitxers i Directoris
Perl Fitxers i Directorisfrankiejol
 
Climbing the Abstract Syntax Tree (PHP South Africa 2017)
Climbing the Abstract Syntax Tree (PHP South Africa 2017)Climbing the Abstract Syntax Tree (PHP South Africa 2017)
Climbing the Abstract Syntax Tree (PHP South Africa 2017)James Titcumb
 
Dip Your Toes in the Sea of Security (PHP South Africa 2017)
Dip Your Toes in the Sea of Security (PHP South Africa 2017)Dip Your Toes in the Sea of Security (PHP South Africa 2017)
Dip Your Toes in the Sea of Security (PHP South Africa 2017)James Titcumb
 
Uncovering Iterators
Uncovering IteratorsUncovering Iterators
Uncovering Iteratorssdevalk
 
Phpで作るmovable typeプラグイン
Phpで作るmovable typeプラグインPhpで作るmovable typeプラグイン
Phpで作るmovable typeプラグインYuji Takayama
 
Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?Julien Vinber
 

Mais procurados (20)

Crazy things done on PHP
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHP
 
20 modules i haven't yet talked about
20 modules i haven't yet talked about20 modules i haven't yet talked about
20 modules i haven't yet talked about
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
 
Random. Kinda.
Random. Kinda.Random. Kinda.
Random. Kinda.
 
Anonymous classes
Anonymous classesAnonymous classes
Anonymous classes
 
The Truth About Lambdas in PHP
The Truth About Lambdas in PHPThe Truth About Lambdas in PHP
The Truth About Lambdas in PHP
 
Gérer vos objets
Gérer vos objetsGérer vos objets
Gérer vos objets
 
distill
distilldistill
distill
 
20160227 Granma
20160227 Granma20160227 Granma
20160227 Granma
 
Dip Your Toes in the Sea of Security (PHP MiNDS January Meetup 2016)
Dip Your Toes in the Sea of Security (PHP MiNDS January Meetup 2016)Dip Your Toes in the Sea of Security (PHP MiNDS January Meetup 2016)
Dip Your Toes in the Sea of Security (PHP MiNDS January Meetup 2016)
 
Communities - Perl edition (RioJS)
Communities - Perl edition (RioJS)Communities - Perl edition (RioJS)
Communities - Perl edition (RioJS)
 
循環参照のはなし
循環参照のはなし循環参照のはなし
循環参照のはなし
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regex
 
Perl Fitxers i Directoris
Perl Fitxers i DirectorisPerl Fitxers i Directoris
Perl Fitxers i Directoris
 
Climbing the Abstract Syntax Tree (PHP South Africa 2017)
Climbing the Abstract Syntax Tree (PHP South Africa 2017)Climbing the Abstract Syntax Tree (PHP South Africa 2017)
Climbing the Abstract Syntax Tree (PHP South Africa 2017)
 
Dip Your Toes in the Sea of Security (PHP South Africa 2017)
Dip Your Toes in the Sea of Security (PHP South Africa 2017)Dip Your Toes in the Sea of Security (PHP South Africa 2017)
Dip Your Toes in the Sea of Security (PHP South Africa 2017)
 
Uncovering Iterators
Uncovering IteratorsUncovering Iterators
Uncovering Iterators
 
Phpで作るmovable typeプラグイン
Phpで作るmovable typeプラグインPhpで作るmovable typeプラグイン
Phpで作るmovable typeプラグイン
 
Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?
 
Ricky Bobby's World
Ricky Bobby's WorldRicky Bobby's World
Ricky Bobby's World
 

Semelhante a Coding Horrors

php global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowAr.pdf
php global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowAr.pdfphp global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowAr.pdf
php global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowAr.pdfanjalitimecenter11
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Kris Wallsmith
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Masahiro Nagano
 
Coding Horrors
Coding HorrorsCoding Horrors
Coding HorrorsMark Baker
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6 brian d foy
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Kang-min Liu
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrowPete McFarlane
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistenceHugo Hamon
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB jhchabran
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic trapsDamien Seguy
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developersStoyan Stefanov
 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)brian d foy
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongersbrian d foy
 
Document Classification In PHP
Document Classification In PHPDocument Classification In PHP
Document Classification In PHPIan Barber
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tourSimon Proctor
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tourSimon Proctor
 
Dip Your Toes in the Sea of Security (CoderCruise 2017)
Dip Your Toes in the Sea of Security (CoderCruise 2017)Dip Your Toes in the Sea of Security (CoderCruise 2017)
Dip Your Toes in the Sea of Security (CoderCruise 2017)James Titcumb
 

Semelhante a Coding Horrors (20)

PHP Tips & Tricks
PHP Tips & TricksPHP Tips & Tricks
PHP Tips & Tricks
 
php global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowAr.pdf
php global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowAr.pdfphp global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowAr.pdf
php global $bsize,$playerToken,$myToken,$gameOver,$winArr,$rowAr.pdf
 
Php functions
Php functionsPhp functions
Php functions
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
Daily notes
Daily notesDaily notes
Daily notes
 
Coding Horrors
Coding HorrorsCoding Horrors
Coding Horrors
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic traps
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongers
 
Document Classification In PHP
Document Classification In PHPDocument Classification In PHP
Document Classification In PHP
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
Dip Your Toes in the Sea of Security (CoderCruise 2017)
Dip Your Toes in the Sea of Security (CoderCruise 2017)Dip Your Toes in the Sea of Security (CoderCruise 2017)
Dip Your Toes in the Sea of Security (CoderCruise 2017)
 

Mais de Mark Baker

Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsMark Baker
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsMark Baker
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsMark Baker
 
Deploying Straight to Production
Deploying Straight to ProductionDeploying Straight to Production
Deploying Straight to ProductionMark Baker
 
Deploying Straight to Production
Deploying Straight to ProductionDeploying Straight to Production
Deploying Straight to ProductionMark Baker
 
Deploying Straight to Production
Deploying Straight to ProductionDeploying Straight to Production
Deploying Straight to ProductionMark Baker
 
A Brief History of Elephpants
A Brief History of ElephpantsA Brief History of Elephpants
A Brief History of ElephpantsMark Baker
 
Aspects of love slideshare
Aspects of love slideshareAspects of love slideshare
Aspects of love slideshareMark Baker
 
Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?Mark Baker
 
A Brief History of ElePHPants
A Brief History of ElePHPantsA Brief History of ElePHPants
A Brief History of ElePHPantsMark Baker
 
Anonymous classes2
Anonymous classes2Anonymous classes2
Anonymous classes2Mark Baker
 
Testing the Untestable
Testing the UntestableTesting the Untestable
Testing the UntestableMark Baker
 
Anonymous Classes: Behind the Mask
Anonymous Classes: Behind the MaskAnonymous Classes: Behind the Mask
Anonymous Classes: Behind the MaskMark Baker
 
Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?Mark Baker
 
Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?Mark Baker
 
Giving birth to an ElePHPant
Giving birth to an ElePHPantGiving birth to an ElePHPant
Giving birth to an ElePHPantMark Baker
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsA Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsMark Baker
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsA Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsMark Baker
 
SPL - The Undiscovered Library - PHPBarcelona 2015
SPL - The Undiscovered Library - PHPBarcelona 2015SPL - The Undiscovered Library - PHPBarcelona 2015
SPL - The Undiscovered Library - PHPBarcelona 2015Mark Baker
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsMark Baker
 

Mais de Mark Baker (20)

Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL Iterators
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL Iterators
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL Iterators
 
Deploying Straight to Production
Deploying Straight to ProductionDeploying Straight to Production
Deploying Straight to Production
 
Deploying Straight to Production
Deploying Straight to ProductionDeploying Straight to Production
Deploying Straight to Production
 
Deploying Straight to Production
Deploying Straight to ProductionDeploying Straight to Production
Deploying Straight to Production
 
A Brief History of Elephpants
A Brief History of ElephpantsA Brief History of Elephpants
A Brief History of Elephpants
 
Aspects of love slideshare
Aspects of love slideshareAspects of love slideshare
Aspects of love slideshare
 
Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?
 
A Brief History of ElePHPants
A Brief History of ElePHPantsA Brief History of ElePHPants
A Brief History of ElePHPants
 
Anonymous classes2
Anonymous classes2Anonymous classes2
Anonymous classes2
 
Testing the Untestable
Testing the UntestableTesting the Untestable
Testing the Untestable
 
Anonymous Classes: Behind the Mask
Anonymous Classes: Behind the MaskAnonymous Classes: Behind the Mask
Anonymous Classes: Behind the Mask
 
Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?
 
Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?Does the SPL still have any relevance in the Brave New World of PHP7?
Does the SPL still have any relevance in the Brave New World of PHP7?
 
Giving birth to an ElePHPant
Giving birth to an ElePHPantGiving birth to an ElePHPant
Giving birth to an ElePHPant
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsA Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP Generators
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsA Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP Generators
 
SPL - The Undiscovered Library - PHPBarcelona 2015
SPL - The Undiscovered Library - PHPBarcelona 2015SPL - The Undiscovered Library - PHPBarcelona 2015
SPL - The Undiscovered Library - PHPBarcelona 2015
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensions
 

Último

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...software pro Development
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 

Último (20)

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 

Coding Horrors

  • 1. Coding Horrors A Horror Film Fan’s Guide to PHP Coding Nightmares
  • 4. Coding Horrors – Friday the 13th
  • 5. Coding Horrors – Friday the 13th // 3 month reports $date_from = date("d-m-Y", strtotime(" -3 months")); $date_to = date('d-m-Y'); $get = "select * from table1 where date between '$date_from' and '$date_to’”; $get_connect = mysqli_query($con2, $get); $get_rows = mysqli_num_rows($get_connect);
  • 8. Coding Horrors – The Ring $studentArray = array(); $query1 = "SELECT * FROM students ORDER BY name"; $studentList = mysqli_query($conn,$query1) or die ("cannot query the table1: " . mysqli_error($conn)); while ($student = mysqli_fetch_array($studentList)) { $studentId = $student['id']; $courses = array(); $query2 = "SELECT * FROM classes WHERE studentid='$studentId'"; $classList = mysqli_query($conn,$query2) or die ("cannot query the table2: " . mysqli_error($conn)); while ($class = mysqli_fetch_array($classList)) { array_push($classes, $class['name']); } array_push($studentArray, array($studentId, $student['name'], implode(', ', $classes))); }
  • 9. Coding Horrors – The Ring SELECT s.id, s.name, group_concat(c.name separator ', ') FROM students s LEFT JOIN classes c ON c.studentid = s.id GROUP BY s.id, s.name ORDER BY s.name;
  • 11. Coding Horrors – The Mummy
  • 12. Coding Horrors – The Mummy $Data = $connection->prepare( "SELECT * FROM :TableName ORDER BY :OrderByColumn :OrderDirection LIMIT 10 OFFSET :Offset" ); $Data->bindValue(':TableName', $TableName, PDO::PARAM_STR); $Data->bindValue(':Offset', $Offset, PDO::PARAM_INT); $Data->bindValue(':OrderByColumn', $OrderColumn, PDO::PARAM_STR); $Data->bindValue(':OrderDirection', $OrderDirection, PDO::PARAM_STR); $Data->execute();
  • 14. Coding Horrors – Night of the Living Dead
  • 15. Coding Horrors – Night of the Living Dead function getAddressDetails() { $data->name = 'Mark'; // $data->address = 'mi casa'; // $data->city = 'Manchester'; // $data->country = 'UK'; // return json_encode($data, JSON_UNESCAPED_UNICODE); return json_encode($data); }
  • 16. Coding Horrors – Night of the Living Dead function addValues($a, $b, $options) { $sum = 0; return $a + $b; }
  • 17. Coding Horrors – Night of the Living Dead function squareIt($bar) { return $bar ** 2; $bar *= $bar; return $bar; }
  • 19. Coding Horrors – The Ring (US Remake)
  • 20. Coding Horrors – The Ring (US Remake) DRY Don’t Repeat Yourself
  • 22. Coding Horrors – The Mummy Returns
  • 23. Coding Horrors – The Mummy Returns $q = "SELECT id, name FROM test WHERE name like '%:foo%'"; $s = "carrot"; $sth = $dbh->prepare($q); $sth->bindParam(':foo', $s); $sth->execute();
  • 24. Coding Horrors – The Mummy Returns $q = "SELECT id, name FROM test WHERE name like :foo"; $s = "carrot"; $s = "%{$s}%"; $sth = $dbh->prepare($q); $sth->bindParam(':foo', $s); $sth->execute();
  • 25. Coding Horrors – The Mummy Returns $q = "SELECT * FROM posts WHERE post_title LIKE :q OR post_text LIKE :q"; $s = "carrot"; $s = "%{$s}%"; $sth = $dbh->prepare($q); $sth->bindParam(':q', $s); $sth->execute();
  • 26. Coding Horrors – The Mummy Returns $q = "SELECT * FROM posts WHERE post_title LIKE :q1 OR post_text LIKE :q2"; $s = "carrot"; $s = "%{$s}%"; $sth = $dbh->prepare($q); $sth->bindParam(':q1', $s); $sth->bindParam(':q2', $s); $sth->execute();
  • 28. Coding Horrors – Halloween
  • 29. Coding Horrors – Halloween function dates() { $startDate = new DateTime(); $endDate = (clone $startDate) ->add(new DateInterval('P1Y')); $dateRange = new DatePeriod($startDate, new DateInterval('P1M'), $endDate); foreach($dateRange as $date) { yield $date; } } foreach(dates() as $date) { echo $date->format("M Y") . PHP_EOL; }
  • 30. Coding Horrors – Halloween Jan 2018 Feb 2018 Mar 2018 Apr 2018 May 2018 Jun 2018 Jul 2018 Aug 2018 Sep 2018 Oct 2018 Nov 2018 Dec 2018 Jan 2018 Mar 2018 Apr 2018 May 2018 Jun 2018 Jul 2018 Aug 2018 Sep 2018 Oct 2018 Nov 2018 Dec 2018 Jan 2019
  • 33. Coding Horrors – Alien if (strpos(" " . $fileURL, "s3://") >= 1) { // Do something }
  • 35. Coding Horrors – Alien if (strpos($fileURL, "s3://") !== false) { // Do something }
  • 38. Coding Horrors – Se7en $calendar = [ 01 => 'January', 02 => 'February', 03 => 'March', 04 => 'April', 05 => 'May', 06 => 'June', 07 => 'July', 08 => 'August', 09 => 'September', 10 => 'October', 11 => 'November', 12 => 'December', ];
  • 39. Coding Horrors – Se7en 1 => January 2 => February 3 => March 4 => April 5 => May 6 => June 7 => July 0 => September 10 => October 11 => November 12 => December
  • 42. Coding Horrors – Scream $sql = "SELECT MAX(id) AS max_page FROM videos"; $result = @$conn->query($sql); $row = @mysql_fetch_array($result); echo $row["max_page"];
  • 44. Coding Horrors – Dawn of the Dead
  • 45. Coding Horrors – Dawn of the Dead /** * Convert a date from PHP to Excel * * @param mixed $dateValue unix timestamp or datetime object * @param string $timezone Optional timezone name for adjustment from UTC * @return mixed Excel date/time value **/ public function PHPToExcel(DateTimeImmutable $dateValue, DateTimeZone $timezone = null) { // Do stuff }
  • 48. Who am I? Mark Baker Design and Development Manager InnovEd (Innovative Solutions for Education) Ltd Coordinator and Developer of: Open Source PHPOffice library PHPExcel (PHPSpreadsheet), PHPWord, PHPPresentation (formerly PHPPowerPoint), PHPProject, PHPVisio Minor contributor to PHP core @Mark_Baker https://github.com/MarkBaker http://uk.linkedin.com/pub/mark-baker/b/572/171 http://markbakeruk.net

Notas do Editor

  1. Friday the 13th
  2. Using varchar for dates in a database table
  3. The Ring (original Japanese version, not the US remake)
  4. Unnecessary (and expensive) loops
  5. Single database query to achieve the same result
  6. The Mummy (1999 version)
  7. Misunderstood bindings
  8. Night of the Living Dead
  9. This is what your version control is for! And if you have to leave commented code in your files, then provide an explanation of why it is commented.
  10. Static Analysis tools should pick this up Don’t rely on PHP’s optimisation to clean up the redundant code, it still impairs readability, and won’t clean up the unused but mandatory $options argument
  11. Static Analysis tools should pick this up too
  12. The Ring (US Remake)
  13. There are times when you simply shouldn’t try to copy a great original
  14. The Mummy Returns
  15. More binding misunderstandings
  16. Can’t duplicate the same named parameter
  17. Can’t duplicate the same named parameter
  18. Halloween
  19. 31st of October
  20. Alien
  21. This code actually works without issue;
  22. BUT the PHP Docs are pretty explicit here....
  23. Symptomatic of a developer that doesn't understand basic PHP Functions, comparisons and datatypes; and/or didn't read the PHP Documentation: when you find an issue like this nesting in the codebase, there are certain to be other problems.
  24. Se7en
  25. Seven is the highest digit in octal notation
  26. Gives a "Parse error: Invalid numeric literal" in PHP7.... What do you mean you're not running php7 yet?
  27. Gives a "Parse error: Invalid numeric literal" in PHP7.... What do you mean you're not running php7 yet?
  28. Scream
  29. Besides the inefficiency of suppressing the errors, this also hides problems
  30. Dawn of the Dead
  31. Docblocks are no longer in synch with the code Building the docs should highlight this mismatch
  32. Don’t let these code smells come back to haunt you again and again
  33. But exorcise them when you find them