SlideShare a Scribd company logo
1 of 28
Basics of PHP
SACHEEN DHANJIE
Sacheen Dhanjie
Senior Developer @ Afrihost.com
What is PHP?
• Hypertext PreProcessor
• Built on C
• Made for the web, but can run on the
command line
• We run all our processing scripts via the
CLI
Variables
• The $ is used to prefix a string, which denotes a variable
• $name = “BOB”; //this assigns the variable
• $sentence = “my name is $name”; // what will this out put?
• $concatenate = “my name is ”.$name; //what will this
output?
• Display information
• echo $sentence;
• print($sentence);
Naming Variables
• $name; // lower case for single words
• $lastName; //camel case for more than one word
• $animalsArray = (‘cow’,’dog’); // not good
• $animals = (‘cow’,’dog’);
• $userObj = new User() // not good
• $user = new User();
• http://www.php-fig.org/psr/
Numbers
• echo 2 + 2; ?
• echo '2' + 2; ?
• ;echo '2' + "2"; ?
• echo 2 + 'c’; ?
Numbers
• Everything in PHP is cast to an integer by default
• echo 2 + 2; //4
• echo '2' + 2; //4
• ;echo '2' + "2"; //4
• echo 2 + 'c’; //2
Casting
• What is casting?
• Casting means making a value a particular type
• $i = 2.332242;
• (int) $i; //2
• (float) $i; // 2.332242
• (string) $i; // 2.332242
Casting
• Why do we care about casting?
• When we interact with data, the language you work with may assume
things
• If you parse and XML message - https://en.wikipedia.org/wiki/XML
• <amount>10.32</amount>
• Using an XML parser, the 10.32 will be assumed as an integer, 10 and
not 10.32
• Casting the value will give you the 10.32
• These things are picked up as you learn to code
Operations
• < //less than
• > //greater than
• <= //less than or equal to
• >= //greater than or equal to
• = //assignment $i =1;
• == //equality (1 == true)
• === //type equlity (1 === true)
• ! //negation - you should be carful (!$bob instanceof
Class) rather (!($bob instanceof Class))
What if $bob?
Bob Ross or just Ross?
What if $bob
• (!$bob)
• If $bob was null; //true
• If $bob was 1; //false
• If $bob was false; //true
• If $bob was 0; //true
Conditions
Conditions
Arrays
Arrays
• Can be used to represent a data source [database, file,
etc.]
• There are many built in functions for arrays.
http://php.net/manual/en/function.array.php
• array_sum($amounts); //R24.23;
• Database queries can be returned as arrays
I hate else
Limit Nesting
Any suggestions to neaten this up?
Limit Nesting
Nesting
• Keep your nesting to a minimal
• The deeper you nest the more complex you code
becomes
• The more it is to debug
• Refactor if your code becomes a mess.
• Make smaller functions for each complex bit.
• Avoid else
• Return early is not a bad thing
Do one thing and do it well
Simple Objects – Object Oriented Programing
• Classes
• Can be instantiated
• Has instance variables
• getters
• Setters [mutators]
• Can be extended
• Accessibility
• - public / private / protected
User Class
Using the User Class
Extend the User Class
Using the Reseller Class
Cool Functions
Something Cool

More Related Content

What's hot (20)

Introduction to php php++
Introduction to php php++Introduction to php php++
Introduction to php php++
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Constructor and encapsulation in php
Constructor and encapsulation in phpConstructor and encapsulation in php
Constructor and encapsulation in php
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive Overview
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
PHP Basic
PHP BasicPHP Basic
PHP Basic
 
Basic PHP
Basic PHPBasic PHP
Basic PHP
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Php
PhpPhp
Php
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
Data Types In PHP
Data Types In PHPData Types In PHP
Data Types In PHP
 
PHP slides
PHP slidesPHP slides
PHP slides
 

Viewers also liked

Mackin lay
Mackin layMackin lay
Mackin laybenjamac
 
Rosendale-Road-Brochure_Final-Web
Rosendale-Road-Brochure_Final-WebRosendale-Road-Brochure_Final-Web
Rosendale-Road-Brochure_Final-WebSabastian Dyer
 
El poder electoral II
El poder electoral IIEl poder electoral II
El poder electoral II25400660y
 
Gionelly_Fernández_Herramientas web 2.0_blog
Gionelly_Fernández_Herramientas web 2.0_blogGionelly_Fernández_Herramientas web 2.0_blog
Gionelly_Fernández_Herramientas web 2.0_blogUniversidad Yacambu
 
1001 libros que leer
1001 libros que leer1001 libros que leer
1001 libros que leerEric Marzochi
 
Dev traning 2016 databases
Dev traning 2016   databasesDev traning 2016   databases
Dev traning 2016 databasesSacheen Dhanjie
 
Formula integral no. 6
Formula integral no. 6Formula integral no. 6
Formula integral no. 6Ceci Guerrero
 
Presentación100
Presentación100Presentación100
Presentación10025400660y
 
Kaufman Research Interests
Kaufman Research InterestsKaufman Research Interests
Kaufman Research InterestsEric Kaufman
 
Workshop #5: Phygital - The Future of Seating by L+W
Workshop #5: Phygital - The Future of Seating by L+WWorkshop #5: Phygital - The Future of Seating by L+W
Workshop #5: Phygital - The Future of Seating by L+Wux singapore
 
Dt Wcdma Validação De Sites WCDMA - Parte 2
Dt Wcdma   Validação De Sites  WCDMA - Parte 2Dt Wcdma   Validação De Sites  WCDMA - Parte 2
Dt Wcdma Validação De Sites WCDMA - Parte 2marco.silva
 
How to choose an idea for your startup Dalton Caldwell Y Combinator
How to choose an idea for your startup  Dalton Caldwell Y CombinatorHow to choose an idea for your startup  Dalton Caldwell Y Combinator
How to choose an idea for your startup Dalton Caldwell Y CombinatorWebrazzi
 

Viewers also liked (18)

Mackin lay
Mackin layMackin lay
Mackin lay
 
Excel 2010
Excel 2010Excel 2010
Excel 2010
 
Autoforma relj-fmmp (1)
Autoforma relj-fmmp (1)Autoforma relj-fmmp (1)
Autoforma relj-fmmp (1)
 
Luciano web
Luciano webLuciano web
Luciano web
 
Rosendale-Road-Brochure_Final-Web
Rosendale-Road-Brochure_Final-WebRosendale-Road-Brochure_Final-Web
Rosendale-Road-Brochure_Final-Web
 
El poder electoral II
El poder electoral IIEl poder electoral II
El poder electoral II
 
Gionelly_Fernández_Herramientas web 2.0_blog
Gionelly_Fernández_Herramientas web 2.0_blogGionelly_Fernández_Herramientas web 2.0_blog
Gionelly_Fernández_Herramientas web 2.0_blog
 
1001 libros que leer
1001 libros que leer1001 libros que leer
1001 libros que leer
 
541 an 15 setembro_2015.ok
541 an 15 setembro_2015.ok541 an 15 setembro_2015.ok
541 an 15 setembro_2015.ok
 
Dev traning 2016 databases
Dev traning 2016   databasesDev traning 2016   databases
Dev traning 2016 databases
 
Formula integral no. 6
Formula integral no. 6Formula integral no. 6
Formula integral no. 6
 
Presentación100
Presentación100Presentación100
Presentación100
 
Scaling
ScalingScaling
Scaling
 
Kaufman Research Interests
Kaufman Research InterestsKaufman Research Interests
Kaufman Research Interests
 
Cv16
Cv16Cv16
Cv16
 
Workshop #5: Phygital - The Future of Seating by L+W
Workshop #5: Phygital - The Future of Seating by L+WWorkshop #5: Phygital - The Future of Seating by L+W
Workshop #5: Phygital - The Future of Seating by L+W
 
Dt Wcdma Validação De Sites WCDMA - Parte 2
Dt Wcdma   Validação De Sites  WCDMA - Parte 2Dt Wcdma   Validação De Sites  WCDMA - Parte 2
Dt Wcdma Validação De Sites WCDMA - Parte 2
 
How to choose an idea for your startup Dalton Caldwell Y Combinator
How to choose an idea for your startup  Dalton Caldwell Y CombinatorHow to choose an idea for your startup  Dalton Caldwell Y Combinator
How to choose an idea for your startup Dalton Caldwell Y Combinator
 

Similar to Dev traning 2016 basics of PHP

Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation TutorialLorna Mitchell
 
MIND sweeping introduction to PHP
MIND sweeping introduction to PHPMIND sweeping introduction to PHP
MIND sweeping introduction to PHPBUDNET
 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Michelangelo van Dam
 
Synapseindia reviews on array php
Synapseindia reviews on array phpSynapseindia reviews on array php
Synapseindia reviews on array phpsaritasingh19866
 
PHP Underground Session 1: The Basics
PHP Underground Session 1: The BasicsPHP Underground Session 1: The Basics
PHP Underground Session 1: The BasicsRobin Hawkes
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackUAnshu Prateek
 
IT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdf
IT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdfIT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdf
IT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdfpkaviya
 
php fundamental
php fundamentalphp fundamental
php fundamentalzalatarunk
 
Php introduction with history of php
Php introduction with history of phpPhp introduction with history of php
Php introduction with history of phppooja bhandari
 
2014 database - course 2 - php
2014 database - course 2 - php2014 database - course 2 - php
2014 database - course 2 - phpHung-yu Lin
 
Building an e:commerce site with PHP
Building an e:commerce site with PHPBuilding an e:commerce site with PHP
Building an e:commerce site with PHPwebhostingguy
 
php programming.pptx
php programming.pptxphp programming.pptx
php programming.pptxrani marri
 

Similar to Dev traning 2016 basics of PHP (20)

Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
 
MIND sweeping introduction to PHP
MIND sweeping introduction to PHPMIND sweeping introduction to PHP
MIND sweeping introduction to PHP
 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010
 
Synapseindia reviews on array php
Synapseindia reviews on array phpSynapseindia reviews on array php
Synapseindia reviews on array php
 
PHP Underground Session 1: The Basics
PHP Underground Session 1: The BasicsPHP Underground Session 1: The Basics
PHP Underground Session 1: The Basics
 
Intro to Perl and Bioperl
Intro to Perl and BioperlIntro to Perl and Bioperl
Intro to Perl and Bioperl
 
Introduction in php
Introduction in phpIntroduction in php
Introduction in php
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackU
 
05php
05php05php
05php
 
IT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdf
IT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdfIT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdf
IT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdf
 
php fundamental
php fundamentalphp fundamental
php fundamental
 
Php introduction with history of php
Php introduction with history of phpPhp introduction with history of php
Php introduction with history of php
 
php
phpphp
php
 
05php
05php05php
05php
 
rtwerewr
rtwerewrrtwerewr
rtwerewr
 
2014 database - course 2 - php
2014 database - course 2 - php2014 database - course 2 - php
2014 database - course 2 - php
 
Building an e:commerce site with PHP
Building an e:commerce site with PHPBuilding an e:commerce site with PHP
Building an e:commerce site with PHP
 
php programming.pptx
php programming.pptxphp programming.pptx
php programming.pptx
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
 

Recently uploaded

英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 

Recently uploaded (20)

英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 

Dev traning 2016 basics of PHP

  • 3. What is PHP? • Hypertext PreProcessor • Built on C • Made for the web, but can run on the command line • We run all our processing scripts via the CLI
  • 4. Variables • The $ is used to prefix a string, which denotes a variable • $name = “BOB”; //this assigns the variable • $sentence = “my name is $name”; // what will this out put? • $concatenate = “my name is ”.$name; //what will this output? • Display information • echo $sentence; • print($sentence);
  • 5. Naming Variables • $name; // lower case for single words • $lastName; //camel case for more than one word • $animalsArray = (‘cow’,’dog’); // not good • $animals = (‘cow’,’dog’); • $userObj = new User() // not good • $user = new User(); • http://www.php-fig.org/psr/
  • 6. Numbers • echo 2 + 2; ? • echo '2' + 2; ? • ;echo '2' + "2"; ? • echo 2 + 'c’; ?
  • 7. Numbers • Everything in PHP is cast to an integer by default • echo 2 + 2; //4 • echo '2' + 2; //4 • ;echo '2' + "2"; //4 • echo 2 + 'c’; //2
  • 8. Casting • What is casting? • Casting means making a value a particular type • $i = 2.332242; • (int) $i; //2 • (float) $i; // 2.332242 • (string) $i; // 2.332242
  • 9. Casting • Why do we care about casting? • When we interact with data, the language you work with may assume things • If you parse and XML message - https://en.wikipedia.org/wiki/XML • <amount>10.32</amount> • Using an XML parser, the 10.32 will be assumed as an integer, 10 and not 10.32 • Casting the value will give you the 10.32 • These things are picked up as you learn to code
  • 10. Operations • < //less than • > //greater than • <= //less than or equal to • >= //greater than or equal to • = //assignment $i =1; • == //equality (1 == true) • === //type equlity (1 === true) • ! //negation - you should be carful (!$bob instanceof Class) rather (!($bob instanceof Class))
  • 11. What if $bob? Bob Ross or just Ross?
  • 12. What if $bob • (!$bob) • If $bob was null; //true • If $bob was 1; //false • If $bob was false; //true • If $bob was 0; //true
  • 16. Arrays • Can be used to represent a data source [database, file, etc.] • There are many built in functions for arrays. http://php.net/manual/en/function.array.php • array_sum($amounts); //R24.23; • Database queries can be returned as arrays
  • 18. Limit Nesting Any suggestions to neaten this up?
  • 20. Nesting • Keep your nesting to a minimal • The deeper you nest the more complex you code becomes • The more it is to debug • Refactor if your code becomes a mess. • Make smaller functions for each complex bit. • Avoid else • Return early is not a bad thing
  • 21. Do one thing and do it well
  • 22. Simple Objects – Object Oriented Programing • Classes • Can be instantiated • Has instance variables • getters • Setters [mutators] • Can be extended • Accessibility • - public / private / protected
  • 24. Using the User Class