SlideShare a Scribd company logo
Starting Out With PHP
Mark Niebergall

https://joind.in/talk/fa612
Starting Out With PHP
Starting Out With PHP
• PHP is a useless language to learn

• PHP is hated by all developers

• PHP is insecure, slow, and not modern

• PHP is bad
Starting Out With PHP
• Lets developers make mistakes

- $password = md5(‘password123’);

- eval($userInput);
Starting Out With PHP
• Lets developers make mistakes

- echo $$variable . $$$variable;

- if (‘true’ == false) {…}
Starting Out With PHP
• Lets developers make mistakes

- $sql = “DELETE FROM users WHERE id =
{$_GET[‘id’]}”;

- “INSERT INTO some_data VALUES (NULL,
‘{$_POST[‘name’]}’);
Starting Out With PHP
• Lets developers make mistakes

- file_get_contents($randomUrl);

- $GLOBALS[‘everything’] = $everything;
Starting Out With PHP
• Lets developers make mistakes

- $oneCase + $two_case + $ThreeCase_More

- if (empty($allTheThings)) {…}
Starting Out With PHP
• Lets developers make mistakes

- if ($a < $b) {

if ($test == true) {

if ($number < 100) {

if (strpos($string, ‘abc’) != 0) {

if ($nestMore == ‘Yes’) {

echo ‘Nesting if statements is great!’;

}

}

}

}

}
Starting Out With PHP
• Lets developers make mistakes

- Works on my box!
Starting Out With PHP
Starting Out With PHP
• PHP runs over 83% of the web

• PHP has an active community

• PHP is secure, fast, and constantly being updated

• PHP is good
About Mark Niebergall
• PHP since 2005

• Masters degree in MIS

• Senior Software Engineer

• Drug screening project

• UPHPU President

• CSSLP, SSCP Certified and SME

• Drones, fishing, skiing, father of 5 boys
Starting Out With PHP
• What is PHP

• Basic Syntax

• Language Features

• PHP Ecosystem
What is PHP
What is PHP
<?php
What is PHP
<?php



echo ‘Hello world!’;

echo “Hello $name”;
What is PHP
<?php



class HelloWorld

{

public function sayHello($name)

{

echo ‘Hello ‘ . $name;

}

}



$helloWorld = new HelloWorld;

$helloWorld->sayHello(‘OpenWest Attendees’);

What is PHP
• Personal Home Page

• Rasmus Lerdorf in 1994

• PHP: Hypertext Preprocessor
What is PHP
• Programming language designed for the Internet

• Server-side scripting language

• General-purpose programming language
What is PHP
• Facebook

• Slack

• Tumblr

• Wikipedia

• News sites

• Blogs
What is PHP
• Open source

- Free to use

- Anyone can contribute

- Source is public
What is PHP
• Written in C

• Compiled at run-time
What is PHP
What is PHP
What is PHP
• Runs with web servers

- Apache

- Nginx
What is PHP
• Interacts with databases

- PostgreSQL

- MySQL

- MSSQL

- Mongo

- Many more
What is PHP
• APIs

• Server

• Mail

• Files
Starting Out With PHP
• What is PHP

• Basic Syntax

• Language Features

• PHP Ecosystem
Basic Syntax
<?php



$variable = ‘something’;

$isSomething = true;

$someInput = $_GET[‘get_key’];
Basic Syntax
<?php



$variable = ‘something’;

$isSomething = true;

$someInput = $_GET[‘get_key’];



if ($isSomething) {

echo $variable;

}
Basic Syntax
<?php



$variable = ‘something’;

$isSomething = true;

$someInput = $_GET[‘get_key’];



if ($isSomething === true || $someInput == ‘Yes’) {

echo $variable;

}
Basic Syntax
<?php



$string = ‘Abc 123’;

$integer = 123;

$float = 123.456;

$bool = true;

$null = null;

$array = [123, 456];

$resource = fopen(‘SomeFile.txt’, ‘r’);

$object = new SomeClass;
Basic Syntax
<?php



$oldArray = array(‘alligator’, ‘bear’, ‘camel’, ‘deer’);



$data = [‘apple’, ‘banana’, ‘carrot’];



$withKeys = [‘test’ => 123, ‘other’ => 456];



foreach ($data as $food) {

echo ‘Eat a ‘ . $food . PHP_EOL;

}
Basic Syntax
<?php



$whatAmI = ‘Drone’;



switch ($whatAmI) {

case ‘Airplane’:

echo ‘Fly far away’;

break;



case ‘Drone’:

case ‘Helicopter’:

echo ‘Fly close by’;

break;

}
Basic Syntax
<?php



$number = 0;



while ($number < 7) {

$number += 1;

}



return $number;
Basic Syntax
<?php



for ($i = 0; $i < 100; $i++) {

…

}
Basic Syntax
<?php



$variable = ‘something’;

$isSomething = true;

$someInput = $_GET[‘get_key’];



function doSomething($variable, $isSomething)

{

if ($isSomething) {

return $variable;

}

return ‘Not something: ‘ . $something;

}
Basic Syntax
<?php



class Cat{}
Basic Syntax
<?php



class Cat {

protected $name;



public function __construct($name) {

$this->name = $name;

}



public function pet() {

return ‘purr’;

}

}
Basic Syntax
<?php



class Cat

{

// Anything can use public

public function pet() {…}



// Cat class and anything inheriting can use protected

protected function speak() {…}



/* only Cat class can use private */

private function _ignoreHuman() {…}

}
Basic Syntax
<?php

abstract class Pet {

protected $name;

abstract public function feed(Food $food);

}



class Cat extend Pet {

public function feed(Food $food) {

return $this->stare($food);

}

protected function stare($thing) {}

}
Basic Syntax
<?php



namespace AnimalPet;



use AnimalHuman;



class Cat

{

public function pet() {…}

protected function speak() {…}

private function _ignoreHuman(Human $human) {…}

}
Basic Syntax
<?php



include(‘Cat.php’);

include_once(‘Dog.php’);



require(‘/../Pet.php’);

require_once(‘/../../Animal.php’);
Basic Syntax
<?php



class AutloadClass

{

public function loadMethod($className)

{

require_once(__DIR__ . ‘/../src/‘ . $className);

}

}



spl_autoload_register([AutoloadClass::class, ‘loadMethod’]);
Basic Syntax
<?php

class Db

{

protected $connection;

public function connect($db, $host, $port, $user, $pwd)

{

$this->connection = new PDO(

‘mysql:dbname=‘ . $db . ‘;host=‘ . $host .

‘;port=‘ . $port’,

$user,

$pwd

);

}

}
Basic Syntax
<?php



// use frameworks for database



$query = $this->getDb()->select()

->from([‘tn’ => ‘table_name’], [‘id’, ‘name’])

->join([‘ot’ => ‘other_table’], ‘ot.id = tn.other_id’,
[‘other_thing’])

->where(‘tn.some_date > ?’, $date)

->where(‘ot.other_number = ?’, $number);



$rows = $this->getDb()->fetchAll($query);
Basic Syntax
<?php



$hashed = password_hash($password,
PASSWORD_DEFAULT);



$isValid = password_verify($userEntered, $hashed);
Starting Out With PHP
• What is PHP

• Basic Syntax

• Language Features

• PHP Ecosystem
Language Features
• Functional

• Object-oriented
Language Features
• Data types

• Type juggling
Language Features
• Method parameter type hinting

• Method return type
Language Features
• Class

• Abstract

• Interface

• Trait
Language Features
• Class

- Constants

- Properties

- Methods

- Magic methods
Language Features
• Class

- class Cat extends Pet implements HousePet {

use MouseCatcherTrait;

const FAMILY = ‘Feline’;

protected $name;

public function __construct($dependencies) {…}

public static function independentAction() {…}

protected function eatFood(Food $food) : Food {…}

private function _controlHuman(Human $human) {…}

}
Language Features
• Abstract

- Class can extend one abstract at a time

- Can have parent, grandparent, etc.

- Mixed functions filled in and others not

- abstract class Pet {

abstract protected function eatFood(Food $food) :
Food {};

}
Language Features
• Interfaces

- Contract

- Class can implement many interfaces

- interface Port {

public function connect(Connection $connection);

}
Language Features
• Trait

- Common characteristics

- trait SomeCharacteristic {

public function doSomething() {…}

}

- class Thing {

use SomeCharacteristic;

}
Language Features
• Exceptions

- try {

…

throw new Exception(‘Error message’);

…

throw new CustomException(‘Failed’);

} catch (Exception | CustomException $e) {

echo $e->getMessage();

}
Language Features
• Magic methods

- Called automatically

- __construct when instantiated

- __set, __get

- __destruct, __call, __callStatic, __isset, __unset,
__sleep, __wakup, __toString, __invoke, __set_state,
__clone, __debugInfo
Language Features
• Namespaces

- namespace AnimalMammalFeline;

use AnimalFish;



class Cat

{

public function eat(Fish $fish) {…}

}

…

new AnimalMammalFelineCat;
Language Features
• Libsodium

- First programming language with modern security
library built-in

- Hash

- Encrypt

- Keys

- Random
PHP Ecosystem
• Frameworks

• Tools

• Community

• Career
PHP Ecosystem
• CMS Frameworks

- Wordpress

- Drupal

- Joomla
PHP Ecosystem
• Frameworks

- larvel

- Symfony

- CakePHP

- Zend

- Slim
PHP Ecosystem
• Frameworks

- Framework Interop Group (PHP-FIG)

‣ Coding standard recommendations

‣ Common interfaces
PHP Ecosystem
• Tools

- composer package manager

‣ packagist repositories

- PECL extension manager
PHP Ecosystem
PHP Ecosystem
• Tools

- PhpStorm

- Zend Studio

- Many other IDEs to choose from

- Any text editor
PHP Ecosystem
• Tools

- PHPUnit

- behat

- phpspec

- Faker
PHP Ecosystem
• Tools

- Xdebug

‣ Step-into debugging

‣ Stacktrace

‣ Performance
PHP Ecosystem
• Tools

- Guzzle

- Apigility
PHP Ecosystem
• Tools

- git

- Mercurial

- Others
PHP Ecosystem
• Community

- User groups

‣ https://www.meetup.com/Utah-PHP-User-Group/

- Conferences

- Magazine
PHP Ecosystem
• Community

- Slack channels

‣ utos.slack.com

‣ phpcommunity.slack.com

‣ phpchat.slack.com

‣ phpug.slack.com
PHP Ecosystem
• Community

- Open source

- Diversity

- Elephpants
PHP Ecosystem
• Community

- Welcoming

- Open to other technologies, languages
PHP Ecosystem
• Career

- Experience

- Education
PHP Ecosystem
• Career

- Lots of jobs

‣ Recruiters

‣ Job boards

‣ Contracts

‣ Who you know
PHP Ecosystem
• Career

- Good pay

‣ $40k-$60k starting

‣ $60k-$80k mid

‣ $80k+ advanced and lead
PHP Ecosystem
• Career

- Local

- Remote
Starting Out With PHP
• What is PHP

• Basic Syntax

• Language Features

• PHP Ecosystem
Questions?
• https://joind.in/talk/fa612
References
• php.net

More Related Content

PDF
Defensive Coding Crash Course Tutorial
PDF
Overview changes in PHP 5.4
PDF
Php Crash Course - Macq Electronique 2010
PDF
Typed Properties and more: What's coming in PHP 7.4?
PPT
MIND sweeping introduction to PHP
PPT
PHP - Introduction to PHP
PDF
Data Types In PHP
PDF
Just-In-Time Compiler in PHP 8
Defensive Coding Crash Course Tutorial
Overview changes in PHP 5.4
Php Crash Course - Macq Electronique 2010
Typed Properties and more: What's coming in PHP 7.4?
MIND sweeping introduction to PHP
PHP - Introduction to PHP
Data Types In PHP
Just-In-Time Compiler in PHP 8

What's hot (20)

PPTX
Introduction in php
PDF
Php Tutorials for Beginners
PPT
PPTX
Introduction in php part 2
PPTX
Object-Oriented Programming with PHP (part 1)
PPTX
Bioinformatics p1-perl-introduction v2013
PPT
Perl Basics for Pentesters Part 1
PPTX
Bioinformatica p6-bioperl
PPT
Class 3 - PHP Functions
PPT
Class 2 - Introduction to PHP
PPT
rtwerewr
PPTX
Bioinformatics p5-bioperl v2013-wim_vancriekinge
PPT
Introduction to php php++
PDF
Cli the other sapi pbc11
PDF
Introduction to Perl and BioPerl
PPT
Introduction to php
KEY
(Parameterized) Roles
PDF
Diving into HHVM Extensions (PHPNW Conference 2015)
KEY
Intermediate PHP
PPT
PHP - Introduction to PHP Functions
Introduction in php
Php Tutorials for Beginners
Introduction in php part 2
Object-Oriented Programming with PHP (part 1)
Bioinformatics p1-perl-introduction v2013
Perl Basics for Pentesters Part 1
Bioinformatica p6-bioperl
Class 3 - PHP Functions
Class 2 - Introduction to PHP
rtwerewr
Bioinformatics p5-bioperl v2013-wim_vancriekinge
Introduction to php php++
Cli the other sapi pbc11
Introduction to Perl and BioPerl
Introduction to php
(Parameterized) Roles
Diving into HHVM Extensions (PHPNW Conference 2015)
Intermediate PHP
PHP - Introduction to PHP Functions
Ad

Similar to Starting Out With PHP (20)

PPTX
PHP Fundamentals: A Comprehensive Introduction
PPT
Phpwebdevelping
PDF
Getting started with php
PDF
Modern php
PPT
phpwebdev.ppt
PPT
Phpwebdev
PPT
Synapse india reviews on php website development
PPTX
Introduction to PHP OOP
PDF
Introduction to PHP
PDF
Essential Guide To Php For All Levels O Adeolu
PPT
PPTX
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
PPT
PHP - Introduction to PHP Fundamentals
PPT
Prersentation
PPT
Synapseindia reviews on array php
PPT
PPT
Synapseindia reviews sharing intro on php
PPT
Synapseindia reviews sharing intro on php
PPT
PHP MySQL Workshop - facehook
PPTX
Day1
PHP Fundamentals: A Comprehensive Introduction
Phpwebdevelping
Getting started with php
Modern php
phpwebdev.ppt
Phpwebdev
Synapse india reviews on php website development
Introduction to PHP OOP
Introduction to PHP
Essential Guide To Php For All Levels O Adeolu
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
PHP - Introduction to PHP Fundamentals
Prersentation
Synapseindia reviews on array php
Synapseindia reviews sharing intro on php
Synapseindia reviews sharing intro on php
PHP MySQL Workshop - facehook
Day1
Ad

More from Mark Niebergall (20)

PDF
Filesystem Management with Flysystem - php[tek] 2023
PDF
Leveling Up With Unit Testing - php[tek] 2023
PDF
Filesystem Management with Flysystem at PHP UK 2023
PDF
Leveling Up With Unit Testing - LonghornPHP 2022
PDF
Developing SOLID Code
PDF
Unit Testing from Setup to Deployment
PDF
Stacking Up Middleware
PDF
BDD API Tests with Gherkin and Behat
PDF
BDD API Tests with Gherkin and Behat
PDF
Hacking with PHP
PDF
Relational Database Design Bootcamp
PDF
Automatic PHP 7 Compatibility Checking Using php7cc (and PHPCompatibility)
PDF
Debugging PHP with Xdebug - PHPUK 2018
PDF
Advanced PHP Simplified - Sunshine PHP 2018
PDF
Inheritance: Vertical or Horizontal
PDF
Cybersecurity State of the Union
PDF
Cryptography With PHP - ZendCon 2017 Workshop
PDF
Defensive Coding Crash Course - ZendCon 2017
PDF
Leveraging Composer in Existing Projects
PDF
Defensive Coding Crash Course
Filesystem Management with Flysystem - php[tek] 2023
Leveling Up With Unit Testing - php[tek] 2023
Filesystem Management with Flysystem at PHP UK 2023
Leveling Up With Unit Testing - LonghornPHP 2022
Developing SOLID Code
Unit Testing from Setup to Deployment
Stacking Up Middleware
BDD API Tests with Gherkin and Behat
BDD API Tests with Gherkin and Behat
Hacking with PHP
Relational Database Design Bootcamp
Automatic PHP 7 Compatibility Checking Using php7cc (and PHPCompatibility)
Debugging PHP with Xdebug - PHPUK 2018
Advanced PHP Simplified - Sunshine PHP 2018
Inheritance: Vertical or Horizontal
Cybersecurity State of the Union
Cryptography With PHP - ZendCon 2017 Workshop
Defensive Coding Crash Course - ZendCon 2017
Leveraging Composer in Existing Projects
Defensive Coding Crash Course

Recently uploaded (20)

PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PDF
Cost to Outsource Software Development in 2025
PDF
17 Powerful Integrations Your Next-Gen MLM Software Needs
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
PPTX
Monitoring Stack: Grafana, Loki & Promtail
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
Download FL Studio Crack Latest version 2025 ?
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
iTop VPN Crack Latest Version Full Key 2025
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Salesforce Agentforce AI Implementation.pdf
PDF
AutoCAD Professional Crack 2025 With License Key
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
PDF
Autodesk AutoCAD Crack Free Download 2025
PDF
Digital Systems & Binary Numbers (comprehensive )
PPTX
Reimagine Home Health with the Power of Agentic AI​
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Cost to Outsource Software Development in 2025
17 Powerful Integrations Your Next-Gen MLM Software Needs
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
Monitoring Stack: Grafana, Loki & Promtail
Navsoft: AI-Powered Business Solutions & Custom Software Development
Oracle Fusion HCM Cloud Demo for Beginners
Download FL Studio Crack Latest version 2025 ?
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
Wondershare Filmora 15 Crack With Activation Key [2025
iTop VPN Crack Latest Version Full Key 2025
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Salesforce Agentforce AI Implementation.pdf
AutoCAD Professional Crack 2025 With License Key
Why Generative AI is the Future of Content, Code & Creativity?
Computer Software and OS of computer science of grade 11.pptx
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
Autodesk AutoCAD Crack Free Download 2025
Digital Systems & Binary Numbers (comprehensive )
Reimagine Home Health with the Power of Agentic AI​

Starting Out With PHP