SlideShare a Scribd company logo
1 of 19
Download to read offline
EdiPHP
The Students PHP meetup




         @EdiPHP
    http://bit.ly/EdiPHP
Structure of Program
●   Syntax
    –   Code between <?php tags ?>
    –   Statements end with “;”
    –   Comments
         ●
             // Single line
         ●
             /* Multi line */
●   Sample
    –   <?php echo “Hello, world”; ?>

                                     @EdiPHP
                                http://bit.ly/EdiPHP
Data Types
●   Boolean – True/False
●   Int – signed numeric integer
●   Float – floating-point
●   String – a collection of binary data
        –   Note Quotes: “this” is different from 'this'
                 ●   A bit.




                                   @EdiPHP
                              http://bit.ly/EdiPHP
Variables
●   Starts with $ sign
    –   Followed with a letter or “_”
●   Dynamically typed
    –   <?php $foobar = “barfoo”; $foobar = 1; $foobar =
        true; ?>
●   Defining if a variable exists
    –   isset($var)


                                 @EdiPHP
                            http://bit.ly/EdiPHP
Arrays
●   Can be constructed following ways:
●
    $var = Array(1,2,3,4,5,6);
●
    $var = Array(‘cat’ => ‘lolcat’, 0 => 4);
●   Or:
          $var = Array();
          $var[] = 'A';
          $var[] = 'B';
●
    Is equivalent to $var = Array (‘A’, ‘B’, ‘c’);
          $var[] = 'c';




                                  @EdiPHP
                             http://bit.ly/EdiPHP
Operators
●   Standard ones (+,-,/,*)
●   Comparison (==,>=, <=,!=, ===, !==)
●   Concatenation .
    –   “foo”.”bar” == “foobar”
●   What happens if you do:
    –   “2” + 5



                                @EdiPHP
                           http://bit.ly/EdiPHP
Loops
●   For
     –   for ($i=0; $i < 4; $i++) { echo $i; }
●   While
     –   while (true) { destroyTheUniverse(); }
●   Do .. while
     –   do { destroyTheUniverse(); } while (false);
●   Foreach
     –   foreach ($arr = Array(‘a’ => ‘b’, ‘c’ => ‘d’) as $key =>
         $value) { echo $key.$value; }
                                    @EdiPHP
                               http://bit.ly/EdiPHP
Functions
●   Begin with reserved word “f u n ct ion ”
●   Can have 0 or more formal parameters
●   Can have optional parameters:
    <?php
    function foobar ($reqParam, $optParam = “bar”)
    {
      echo $reqParam.’ foo’.$optParam;
    }
    ?>

                                  @EdiPHP
                             http://bit.ly/EdiPHP
OOP
●   PHP has objects like java, cpp does
●
    Reserved word for class is “class”
●   Have good old public, private, etc. and static,
    final, etc. methods




                            @EdiPHP
                       http://bit.ly/EdiPHP
Structure of a class
<?
class foobar
{
    private $privVar = 15;
    public function getPrivVar ()
    {
        return $this->privVar;
    }
}
                                      @EdiPHP
?>                               http://bit.ly/EdiPHP
Real world examples (1)
●       Bad word filtering
        –   A function that converts all occurrences of
            “LOLSoc” to “CompSoc”
<?php
    function filterBadWords($input)
    {
        return str_replace(‘LOLSoc’, ‘CompSoc’, $input);
    }
?>
                                     @EdiPHP
                                http://bit.ly/EdiPHP
Real World examples (2)
    ●    Calculating sum of digits in array
<?php

$arr = array(1,2,3,4,5,6,7,-6);

function sumDigits ($a)

{

    $sum = 0;

    for ($i=0; $i < count($a); $i++)

    {

        $sum += $a[$i];

    }

    return $sum;
                                            @EdiPHP
}
                                       http://bit.ly/EdiPHP
Real World Examples (3)
●   Creating a class society
    –   Which has a name
●   That is a useless class, though, that's the best
    that fits into slide :)




                                @EdiPHP
                           http://bit.ly/EdiPHP
<?php
         Real World Examples (3)
 Class society
                                          function setName($name)
 {                                        {
     private $_name;                          $this->$_name = $name;
     function setName($name)
                                              return $this;
                                          }
     {


         $this->$_name = $name;




                                          public function getName()
         return $this;


     }


     public function getName()            {
     {
                                            return $this->getName();
                                          }
         return $this->getName();


     }


     public function __construct($name)


     {


         $this->setName($name);


     }


 }
                                                      @EdiPHP
?>                                               http://bit.ly/EdiPHP
Extending the previous
               example
    ●   Making it echo
    ●   Add following method to class:
public function __toString()

{

    echo $this->getName();

}




                                    @EdiPHP
                               http://bit.ly/EdiPHP
A bit about static methods
    ●    To define a static function:
public static function foobar ()
{
        return “foobar”;
}
    ●    To call a static function
               –   From outside the class scope: className::function()
               –   From inside the class: self::function()

                                         @EdiPHP
                                    http://bit.ly/EdiPHP
Questions




      @EdiPHP
 http://bit.ly/EdiPHP
Tasks
●   Yes, we have them.
●   Please try to do them until next meetup, where
    we'll discuss the solutions.




                           @EdiPHP
                      http://bit.ly/EdiPHP
EdiPHP
The Students PHP meetup




         @EdiPHP
    http://bit.ly/EdiPHP

More Related Content

What's hot

PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
jsmith92
 

What's hot (20)

PHP - Introduction to PHP
PHP -  Introduction to PHPPHP -  Introduction to PHP
PHP - Introduction to PHP
 
php 2 Function creating, calling, PHP built-in function
php 2 Function creating, calling,PHP built-in functionphp 2 Function creating, calling,PHP built-in function
php 2 Function creating, calling, PHP built-in function
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
 
Introduction in php part 2
Introduction in php part 2Introduction in php part 2
Introduction in php part 2
 
Introduction in php
Introduction in phpIntroduction in php
Introduction in php
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Ruby 2.0
Ruby 2.0Ruby 2.0
Ruby 2.0
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 
Findbin libs
Findbin libsFindbin libs
Findbin libs
 
PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)
 
Object-Oriented Programming with PHP (part 1)
Object-Oriented Programming with PHP (part 1)Object-Oriented Programming with PHP (part 1)
Object-Oriented Programming with PHP (part 1)
 
Introduction to web and php mysql
Introduction to web and php mysqlIntroduction to web and php mysql
Introduction to web and php mysql
 
Php my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netPhp my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.net
 
Shell Scripting Tutorial | Edureka
Shell Scripting Tutorial | EdurekaShell Scripting Tutorial | Edureka
Shell Scripting Tutorial | Edureka
 
Subroutines
SubroutinesSubroutines
Subroutines
 
Metadata-driven Testing
Metadata-driven TestingMetadata-driven Testing
Metadata-driven Testing
 
Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)
Puppet Camp Paris 2015: Power of Puppet 4 (Beginner) Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)
Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)
 
Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013
 

Viewers also liked

Task 2
Task 2Task 2
Task 2
EdiPHP
 
Task 03
Task 03Task 03
Task 03
EdiPHP
 
01 - First Meetup
01 - First Meetup01 - First Meetup
01 - First Meetup
EdiPHP
 
03 - Third Meetup
03 - Third Meetup03 - Third Meetup
03 - Third Meetup
EdiPHP
 
Task 1
Task 1Task 1
Task 1
EdiPHP
 
Managing Religious Tourism Abstracts
Managing Religious Tourism   AbstractsManaging Religious Tourism   Abstracts
Managing Religious Tourism Abstracts
eon
 
Ppt Ingles
Ppt InglesPpt Ingles
Ppt Ingles
valef94
 
Trabajo Excel Mate
Trabajo Excel MateTrabajo Excel Mate
Trabajo Excel Mate
valef94
 
Collaborative Learning Solutions
Collaborative Learning SolutionsCollaborative Learning Solutions
Collaborative Learning Solutions
MaartenGKN
 

Viewers also liked (18)

Web Based Workforce Training Presentation
Web Based Workforce Training PresentationWeb Based Workforce Training Presentation
Web Based Workforce Training Presentation
 
ACTIVIDAD 2
ACTIVIDAD 2ACTIVIDAD 2
ACTIVIDAD 2
 
Task 2
Task 2Task 2
Task 2
 
Task 03
Task 03Task 03
Task 03
 
Why Renting Isn't Throwing Money Away | Scott Dilloff
Why Renting Isn't Throwing Money Away | Scott DilloffWhy Renting Isn't Throwing Money Away | Scott Dilloff
Why Renting Isn't Throwing Money Away | Scott Dilloff
 
Lucky
LuckyLucky
Lucky
 
01 - First Meetup
01 - First Meetup01 - First Meetup
01 - First Meetup
 
03 - Third Meetup
03 - Third Meetup03 - Third Meetup
03 - Third Meetup
 
Task 1
Task 1Task 1
Task 1
 
Let's Order TACOS!
Let's Order TACOS!Let's Order TACOS!
Let's Order TACOS!
 
zellers
zellerszellers
zellers
 
Tornadoes keynote1
Tornadoes keynote1Tornadoes keynote1
Tornadoes keynote1
 
Fit4 Business
Fit4 BusinessFit4 Business
Fit4 Business
 
Historical Development Patterns
Historical Development PatternsHistorical Development Patterns
Historical Development Patterns
 
Managing Religious Tourism Abstracts
Managing Religious Tourism   AbstractsManaging Religious Tourism   Abstracts
Managing Religious Tourism Abstracts
 
Ppt Ingles
Ppt InglesPpt Ingles
Ppt Ingles
 
Trabajo Excel Mate
Trabajo Excel MateTrabajo Excel Mate
Trabajo Excel Mate
 
Collaborative Learning Solutions
Collaborative Learning SolutionsCollaborative Learning Solutions
Collaborative Learning Solutions
 

Similar to 02 - Second meetup

Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
Iftekhar Eather
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
jsmith92
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
Nat Weerawan
 

Similar to 02 - Second meetup (20)

OOP is more than Cars and Dogs
OOP is more than Cars and Dogs OOP is more than Cars and Dogs
OOP is more than Cars and Dogs
 
OOP
OOPOOP
OOP
 
Giới thiệu PHP 7
Giới thiệu PHP 7Giới thiệu PHP 7
Giới thiệu PHP 7
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
Starting Out With PHP
Starting Out With PHPStarting Out With PHP
Starting Out With PHP
 
Elements of Functional Programming in PHP
Elements of Functional Programming in PHPElements of Functional Programming in PHP
Elements of Functional Programming in PHP
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
 
PHP Performance Trivia
PHP Performance TriviaPHP Performance Trivia
PHP Performance Trivia
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
06-classes.ppt (copy).pptx
06-classes.ppt (copy).pptx06-classes.ppt (copy).pptx
06-classes.ppt (copy).pptx
 
Intro to PHP
Intro to PHPIntro to PHP
Intro to PHP
 
08 Advanced PHP #burningkeyboards
08 Advanced PHP #burningkeyboards08 Advanced PHP #burningkeyboards
08 Advanced PHP #burningkeyboards
 
Modern php
Modern phpModern php
Modern php
 
Mastering Namespaces in PHP
Mastering Namespaces in PHPMastering Namespaces in PHP
Mastering Namespaces in PHP
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
 

Recently uploaded

Recently uploaded (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

02 - Second meetup

  • 1. EdiPHP The Students PHP meetup @EdiPHP http://bit.ly/EdiPHP
  • 2. Structure of Program ● Syntax – Code between <?php tags ?> – Statements end with “;” – Comments ● // Single line ● /* Multi line */ ● Sample – <?php echo “Hello, world”; ?> @EdiPHP http://bit.ly/EdiPHP
  • 3. Data Types ● Boolean – True/False ● Int – signed numeric integer ● Float – floating-point ● String – a collection of binary data – Note Quotes: “this” is different from 'this' ● A bit. @EdiPHP http://bit.ly/EdiPHP
  • 4. Variables ● Starts with $ sign – Followed with a letter or “_” ● Dynamically typed – <?php $foobar = “barfoo”; $foobar = 1; $foobar = true; ?> ● Defining if a variable exists – isset($var) @EdiPHP http://bit.ly/EdiPHP
  • 5. Arrays ● Can be constructed following ways: ● $var = Array(1,2,3,4,5,6); ● $var = Array(‘cat’ => ‘lolcat’, 0 => 4); ● Or: $var = Array(); $var[] = 'A'; $var[] = 'B'; ● Is equivalent to $var = Array (‘A’, ‘B’, ‘c’); $var[] = 'c'; @EdiPHP http://bit.ly/EdiPHP
  • 6. Operators ● Standard ones (+,-,/,*) ● Comparison (==,>=, <=,!=, ===, !==) ● Concatenation . – “foo”.”bar” == “foobar” ● What happens if you do: – “2” + 5 @EdiPHP http://bit.ly/EdiPHP
  • 7. Loops ● For – for ($i=0; $i < 4; $i++) { echo $i; } ● While – while (true) { destroyTheUniverse(); } ● Do .. while – do { destroyTheUniverse(); } while (false); ● Foreach – foreach ($arr = Array(‘a’ => ‘b’, ‘c’ => ‘d’) as $key => $value) { echo $key.$value; } @EdiPHP http://bit.ly/EdiPHP
  • 8. Functions ● Begin with reserved word “f u n ct ion ” ● Can have 0 or more formal parameters ● Can have optional parameters: <?php function foobar ($reqParam, $optParam = “bar”) { echo $reqParam.’ foo’.$optParam; } ?> @EdiPHP http://bit.ly/EdiPHP
  • 9. OOP ● PHP has objects like java, cpp does ● Reserved word for class is “class” ● Have good old public, private, etc. and static, final, etc. methods @EdiPHP http://bit.ly/EdiPHP
  • 10. Structure of a class <? class foobar { private $privVar = 15; public function getPrivVar () { return $this->privVar; } } @EdiPHP ?> http://bit.ly/EdiPHP
  • 11. Real world examples (1) ● Bad word filtering – A function that converts all occurrences of “LOLSoc” to “CompSoc” <?php function filterBadWords($input) { return str_replace(‘LOLSoc’, ‘CompSoc’, $input); } ?> @EdiPHP http://bit.ly/EdiPHP
  • 12. Real World examples (2) ● Calculating sum of digits in array <?php $arr = array(1,2,3,4,5,6,7,-6); function sumDigits ($a) { $sum = 0; for ($i=0; $i < count($a); $i++) { $sum += $a[$i]; } return $sum; @EdiPHP } http://bit.ly/EdiPHP
  • 13. Real World Examples (3) ● Creating a class society – Which has a name ● That is a useless class, though, that's the best that fits into slide :) @EdiPHP http://bit.ly/EdiPHP
  • 14. <?php Real World Examples (3) Class society function setName($name) { { private $_name; $this->$_name = $name; function setName($name) return $this; } { $this->$_name = $name; public function getName() return $this; } public function getName() { { return $this->getName(); } return $this->getName(); } public function __construct($name) { $this->setName($name); } } @EdiPHP ?> http://bit.ly/EdiPHP
  • 15. Extending the previous example ● Making it echo ● Add following method to class: public function __toString() { echo $this->getName(); } @EdiPHP http://bit.ly/EdiPHP
  • 16. A bit about static methods ● To define a static function: public static function foobar () { return “foobar”; } ● To call a static function – From outside the class scope: className::function() – From inside the class: self::function() @EdiPHP http://bit.ly/EdiPHP
  • 17. Questions @EdiPHP http://bit.ly/EdiPHP
  • 18. Tasks ● Yes, we have them. ● Please try to do them until next meetup, where we'll discuss the solutions. @EdiPHP http://bit.ly/EdiPHP
  • 19. EdiPHP The Students PHP meetup @EdiPHP http://bit.ly/EdiPHP