SlideShare une entreprise Scribd logo
1  sur  17
PHP Basic Part 2




    www.prodigyview.com
Overview
Objective

For beginners to further their knowledge of PHP by
providing a greater understanding of objects and
functions.

Requirements

 Understanding of variables, methods and classes
Estimated Time

8 minutes


                     www.prodigyview.com
Follow Along With A Code
          Example
1. Download a copy of the example code at
  www.prodigyview.com/source.

2. Install the system in an environment you feel
  comfortable testing in.

3. Proceed to examples/basics/PHP_Basics.php




                   http://www.prodigyview.com
Concepts Covered
 Static Methods
 Public Methods
 Protected Methods
 Private Methods
 Anonymous Functions




                      www.prodigyview.com
Static Methods
So you’ve come to the point after PHP Basics Part 1, that you are
ready to dive a little deeper. Who am I to hold you back?

If you remember from part 1, we worked with objects with methods.
Now we are going to work with objects that have static methods.

What is a static method?

A static method is a method that can be called without instantiating
the object. Simply put, we can access the method without using
‘new Object()’. Static methods are accessed by using this syntax:
‘class_name ::method_name’ .



                           www.prodigyview.com
Static Method Example
1. Define a method as Static
                Creating A Static Method




              Executing A Static Method


  2. Use the ‘::’ to call/execute the method
Public Methods
In our last slide we created a method and also declared it
as public. A method that is ‘public’ means that any other
user outside the object can call the function. Here is the
code again on declaring a static method.




                          Sets the method as public
Protected Methods
Next up, protected methods. These methods differ from
public methods in that only another method inside the
current object can call this method. Protected methods
can also be called by children classes when they are
extended. We will get into extending a class into a minute.




                   Sets the method as protected
Private Methods
And finally we get to private methods. Private methods
are like protected methods in that only another method
inside the class can call it. But they differ from protected
methods in that they cannot to be extended.




                   Sets the method as private
Our Class




www.prodigyview.com
Extending A Class
So far it’s been mentioned twice about extending a class.

What does this mean?

Extending a class mean that you can create another class
and give all the public and protected properties of one
class to another class. Private methods CANNOT be
given to another class.

So we have the class ParentObject. Let us give(extend)
it’s methods to another class.



                     www.prodigyview.com
Extending ParentObject




          Calls the protected function of ParentObject

       www.prodigyview.com
Anonymous Functions
Finally for this tutorial we have anonymous functions,
which are also known as closures.

These are functions that be created on the fly and do not
have to be actually declared until needed. Anonymous
functions can also be stored in a variable, which can be
stored in an array and passed to functions and methods.
Let’s create a simple closure.




                     www.prodigyview.com
Creating and Storing Closure
1. Assign the function to a variable




                                2. Calls the function through the variable
                               www.prodigyview.com
Challenge!
To better understand the concepts presented, an optional
challenge is being presented.

Your challenge for this tutorial is to create a class that has
a static protected method. That static method will have an
anonymous function that adds two variables and returns
the value of the variables added.

Extended that class to another and through a public
method, call the protected one.




                       www.prodigyview.com
Review
1. Static methods are accessed with ‘::’ operator.
2. Objects do not have to be instantiated to use a static
   method.
3. Public methods are accessible by everyone.
4. Protected methods are also accessible to other methods
   within the object and children classes.
5. Private methods are only accessible to methods within the
   current class.
6. Closures/Anonymous Functions can be assigned to a
   variable.



                       www.prodigyview.com
More Tutorials
For more tutorials, please visit:

http://www.prodigyview.com/tutorials




                     www.prodigyview.com

Contenu connexe

Similaire à Learning PHP Basics Part 2

Similaire à Learning PHP Basics Part 2 (20)

Creating Dynamic Objects PHP
Creating Dynamic Objects PHPCreating Dynamic Objects PHP
Creating Dynamic Objects PHP
 
OOP presentation.pptx
OOP presentation.pptxOOP presentation.pptx
OOP presentation.pptx
 
Object oreinted php | OOPs
Object oreinted php | OOPsObject oreinted php | OOPs
Object oreinted php | OOPs
 
OOP_presentation.pptx
OOP_presentation.pptxOOP_presentation.pptx
OOP_presentation.pptx
 
Java sessionnotes
Java sessionnotesJava sessionnotes
Java sessionnotes
 
Lecture 17
Lecture 17Lecture 17
Lecture 17
 
(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP
 
Beginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPBeginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHP
 
Chapter 8 java
Chapter 8 javaChapter 8 java
Chapter 8 java
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
 
Lesson 13 object and class
Lesson 13 object and classLesson 13 object and class
Lesson 13 object and class
 
OOP in Java Presentation.pptx
OOP in Java Presentation.pptxOOP in Java Presentation.pptx
OOP in Java Presentation.pptx
 
Python_Unit_3.pdf
Python_Unit_3.pdfPython_Unit_3.pdf
Python_Unit_3.pdf
 
The Ring programming language version 1.5.1 book - Part 68 of 180
The Ring programming language version 1.5.1 book - Part 68 of 180The Ring programming language version 1.5.1 book - Part 68 of 180
The Ring programming language version 1.5.1 book - Part 68 of 180
 
Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1
 
This and Static Keyword
This and Static KeywordThis and Static Keyword
This and Static Keyword
 
chapter 5 concepts of object oriented programming
chapter 5 concepts of object oriented programmingchapter 5 concepts of object oriented programming
chapter 5 concepts of object oriented programming
 
Java unit 7
Java unit 7Java unit 7
Java unit 7
 
Object_oriented_programming_OOP_with_PHP.pdf
Object_oriented_programming_OOP_with_PHP.pdfObject_oriented_programming_OOP_with_PHP.pdf
Object_oriented_programming_OOP_with_PHP.pdf
 
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesUNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
 

Plus de ProdigyView

Plus de ProdigyView (20)

Installing Plug-ins
Installing Plug-insInstalling Plug-ins
Installing Plug-ins
 
Building An Application
Building An ApplicationBuilding An Application
Building An Application
 
Installing Applications
Installing ApplicationsInstalling Applications
Installing Applications
 
Video Content Management
Video Content ManagementVideo Content Management
Video Content Management
 
Audio Content Management
Audio Content ManagementAudio Content Management
Audio Content Management
 
File Content Management
File Content ManagementFile Content Management
File Content Management
 
Email Configuration
Email ConfigurationEmail Configuration
Email Configuration
 
HTML5 Tags and Elements Tutorial
HTML5 Tags and Elements TutorialHTML5 Tags and Elements Tutorial
HTML5 Tags and Elements Tutorial
 
HTML Forms Tutorial
HTML Forms TutorialHTML Forms Tutorial
HTML Forms Tutorial
 
Html Tags Tutorial
Html Tags TutorialHtml Tags Tutorial
Html Tags Tutorial
 
Video Conversion PHP
Video Conversion PHPVideo Conversion PHP
Video Conversion PHP
 
Sending Email Basics PHP
Sending Email Basics PHPSending Email Basics PHP
Sending Email Basics PHP
 
Tools ProdigyView
Tools ProdigyViewTools ProdigyView
Tools ProdigyView
 
Custom Validation PHP
Custom Validation PHPCustom Validation PHP
Custom Validation PHP
 
Basic File Cache Tutorial - PHP
Basic File Cache Tutorial - PHPBasic File Cache Tutorial - PHP
Basic File Cache Tutorial - PHP
 
Understanding Web Cache
Understanding Web CacheUnderstanding Web Cache
Understanding Web Cache
 
Javascript And CSS Libraries
Javascript And CSS LibrariesJavascript And CSS Libraries
Javascript And CSS Libraries
 
SQL Prepared Statements Tutorial
SQL Prepared Statements TutorialSQL Prepared Statements Tutorial
SQL Prepared Statements Tutorial
 
Database Basics
Database BasicsDatabase Basics
Database Basics
 
Implementing the Adapter Design Pattern
Implementing the Adapter Design PatternImplementing the Adapter Design Pattern
Implementing the Adapter Design Pattern
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 

Learning PHP Basics Part 2

  • 1. PHP Basic Part 2 www.prodigyview.com
  • 2. Overview Objective For beginners to further their knowledge of PHP by providing a greater understanding of objects and functions. Requirements  Understanding of variables, methods and classes Estimated Time 8 minutes www.prodigyview.com
  • 3. Follow Along With A Code Example 1. Download a copy of the example code at www.prodigyview.com/source. 2. Install the system in an environment you feel comfortable testing in. 3. Proceed to examples/basics/PHP_Basics.php http://www.prodigyview.com
  • 4. Concepts Covered  Static Methods  Public Methods  Protected Methods  Private Methods  Anonymous Functions www.prodigyview.com
  • 5. Static Methods So you’ve come to the point after PHP Basics Part 1, that you are ready to dive a little deeper. Who am I to hold you back? If you remember from part 1, we worked with objects with methods. Now we are going to work with objects that have static methods. What is a static method? A static method is a method that can be called without instantiating the object. Simply put, we can access the method without using ‘new Object()’. Static methods are accessed by using this syntax: ‘class_name ::method_name’ . www.prodigyview.com
  • 6. Static Method Example 1. Define a method as Static Creating A Static Method Executing A Static Method 2. Use the ‘::’ to call/execute the method
  • 7. Public Methods In our last slide we created a method and also declared it as public. A method that is ‘public’ means that any other user outside the object can call the function. Here is the code again on declaring a static method. Sets the method as public
  • 8. Protected Methods Next up, protected methods. These methods differ from public methods in that only another method inside the current object can call this method. Protected methods can also be called by children classes when they are extended. We will get into extending a class into a minute. Sets the method as protected
  • 9. Private Methods And finally we get to private methods. Private methods are like protected methods in that only another method inside the class can call it. But they differ from protected methods in that they cannot to be extended. Sets the method as private
  • 11. Extending A Class So far it’s been mentioned twice about extending a class. What does this mean? Extending a class mean that you can create another class and give all the public and protected properties of one class to another class. Private methods CANNOT be given to another class. So we have the class ParentObject. Let us give(extend) it’s methods to another class. www.prodigyview.com
  • 12. Extending ParentObject Calls the protected function of ParentObject www.prodigyview.com
  • 13. Anonymous Functions Finally for this tutorial we have anonymous functions, which are also known as closures. These are functions that be created on the fly and do not have to be actually declared until needed. Anonymous functions can also be stored in a variable, which can be stored in an array and passed to functions and methods. Let’s create a simple closure. www.prodigyview.com
  • 14. Creating and Storing Closure 1. Assign the function to a variable 2. Calls the function through the variable www.prodigyview.com
  • 15. Challenge! To better understand the concepts presented, an optional challenge is being presented. Your challenge for this tutorial is to create a class that has a static protected method. That static method will have an anonymous function that adds two variables and returns the value of the variables added. Extended that class to another and through a public method, call the protected one. www.prodigyview.com
  • 16. Review 1. Static methods are accessed with ‘::’ operator. 2. Objects do not have to be instantiated to use a static method. 3. Public methods are accessible by everyone. 4. Protected methods are also accessible to other methods within the object and children classes. 5. Private methods are only accessible to methods within the current class. 6. Closures/Anonymous Functions can be assigned to a variable. www.prodigyview.com
  • 17. More Tutorials For more tutorials, please visit: http://www.prodigyview.com/tutorials www.prodigyview.com