SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Ähnlich wie Learning PHP Basics Part 2

Ähnlich wie 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
 

Mehr von ProdigyView

Mehr von 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
 

Kürzlich hochgeladen

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

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
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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)
 
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...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 

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