SlideShare uma empresa Scribd logo
1 de 55
Baixar para ler offline
Introduction to Object Oriented PHP

                       Function Junction
Mike Pavlak
Solutions Consultant
mike.p@zend.com
(815) 722 3454

To watch the webinar please go to:
http://www.zend.com/en/webinar/IBMi/70170000000bZBj-webinar-intro-to-
oop-for-ibm-i-20110601.flv
                                                       © All rights reserved. Zend Technologies, Inc.
Foundations course
                                                                               starting next week!
                                                                               Call your account manager
                                                                               or go to the Zend website:
                                                                               http://shop.zend.com/en
                                                                               /php-training.html




2                             © All rights reserved. Zend Technologies, Inc.
    Insert->Header & Footer
Join us at ZendCon
The premier PHP conference!
October 17-19, 2011 – Santa Clara, CA


 Conference Highlights                                                       Conference Topics
 • Learn PHP best practices for architecture, design                         • Architecture & Design
   and development                                                           • Expanding Horizons
 • Technical sessions for all knowledge levels                               • IBM i
 • In-depth tutorials for advanced learning                                  • Lifecycle Best Practices
                                                                             • NoSQL / Alternative Stores / Search
 • PHP Certification courses and testing                                     • PHP Development
 • Exhibit hall showcasing the latest products                               • Server/Operations
 • Networking opportunities with peers and luminaries                        • SQL
                                                                             • Zend Framework
                                        www.zendcon.com
                                       © All rights reserved. Zend Technologies, Inc.
Audience
    • New to PHP
    • New to Object Oriented Design
    • Open to new ideas and methods
    • This is not a DEEP DIVE
          Relax and enjoy the ride!




4   Insert->Header & Footer            © All rights reserved. Zend Technologies, Inc.
Agenda
    • Quick review of PHP basics
    • The class and its object
    • Components of an object
         Properties

         Methods
    • Other OO stuff
    • I don’t know OO: Get Started NOW!




5   Insert->Header & Footer      © All rights reserved. Zend Technologies, Inc.
Roadmap to Expert PHP
   RPG Green Screen  PHP Expert
   Start somewhere! Here isn’t bad!
   Path
       Procedural PHP
       OO PHP
       Zend Framework (or another)
       PHP Certification




                            © All rights reserved. Zend Technologies, Inc.
Questions?

• Let’s keep it interactive!




• Follow us!
  http://bit.ly/cjueZg (Zend Technologies or search for Zend)



  http://twitter.com/zend




                        © All rights reserved. Zend Technologies, Inc.
Introduction to OO PHP
www.zend.com




 Quick review of PHP basics




                © All rights reserved. Zend Technologies, Inc.
Variables
                                                                                                        <?php
      • Rules
           Case senstive
                                                                                                        $field1 = 5;
                                                                                                        $field2 = 10;
           Begin with $                                                                                $field3 = $field1 + $field2;

                • $thisIsMyVariable                                                                     ?>
                • $__AnotherVariable
                • $ this is not a variable
           Implicit casting

           Can be re-typed (Dynamically Typed Language)

      • Constant – Variable that doesn’t change
           Define(„TEACHER‟, “Mike Pavlak”);


| 9   Modernizing legacy applications on i5 with PHP   © All rights reserved. Zend Technologies, Inc.                                  |
Variables and their types
      • Scalar
            Integer
                  • -2,147,483,648 thru 2,147,483,647
                  • Supports decimal, octal and hex representation

            Floating-Point
                  • 1.7E-308 thru 1.7E+308
                  • 15 digits of decimal precision

            Strings

                  • Big. Really big. Too big to discuss!

            Boolean
                  • False is 0, 0.0, false keyword, empty string, object w/no values, null. All
                    others are true

      • Object, array, null and resource
 |
10
     Modernizing legacy applications on i5 with PHP   © All rights reserved. Zend Technologies, Inc.   |
Variables…(cont.)

     • Scope
          Global – Available everywhere but inside function (sort of)

          Local – Available only in a function, destroyed at end

          Static – Available only in a function, but remains



     • Arrays (three types)
          Enumerated

          Associative

          Multi-dimensional



 |
11
     Modernizing legacy applications on i5 with PHP   © All rights reserved. Zend Technologies, Inc.   |
Functions
          Functions come from 1 of 3 places
              Built-in
                     Part of base PHP

              Extensions
                     Components of modules like image functions in GD

              User defined
                     You will create these!

          You may have been using functions…
              db2_connect()
              print_r
              strtoupper
              Etc.
 |
12
                                    © All rights reserved. Zend Technologies, Inc.   02/03
What do functions look like?


Function call has three major parts:
Function Name - Required
Parameters - Optional
Return Value – Always returned, default null




  Return   Function Name                                             Parameters




                    © All rights reserved. Zend Technologies, Inc.
Scope
• Variables have scope, much like RPG ILE
  • Function keeps its own set of variables

  • Global keyword can change all that (RPG III)

  • Better to pass, globals can‟t be trusted

• Static variables
  • Persistence from call to call




                          © All rights reserved. Zend Technologies, Inc.
Parameters

• Default
 • Assign value in interface

• Pass by value
 • This is the default behavior

• Pass by reference
 • This is done with & before the variable in the interface.

• Variable number
 • func_get_args()

 • func_num_args()

 • func_get_arg(argument_#)


                       © All rights reserved. Zend Technologies, Inc.
Introduction to OO PHP
www.zend.com




 The class and its object




                 © All rights reserved. Zend Technologies, Inc.
Concepts

       • Keywords
            class

            function

            static

       • Concepts
            Class

            Instance

            Magic Methods

            Visibility


   |
                                                                                |
 23-
       Name of this section   © All rights reserved. Zend Technologies, Inc.   17
Aug-
RELAX!!!

       You may not be comfortable with the more modern structure


                              Don’t feel like you NEED to follow it


                       Take your time learning it. PHP lets you do this




   |
                                                                                         |
 23-
       Name of this section            © All rights reserved. Zend Technologies, Inc.   18
Aug-
Bare minimum

       • Keep library files out of the document root
       • Always name your PHP files .php
       • Keep data out of the document root
       • Do not deploy with a phpinfo.php file
            Do a Google search for “inurl:phpinfo.php”

       • Do not allow the web server to write to the document root
       • Always validate your input.
            Do a Google search for “inurl:page=home.php”




   |
                                                                                   |
 23-
       Name of this section      © All rights reserved. Zend Technologies, Inc.   19
Aug-
Object Model

   Object is centered around data, not logic
       Think about your RPG programs
       You manipulate data.
       Very few programs that have no data access


   Object Definition:
       Data structure with functions and variables local to
        each object.
       Keep routines similar to data element together

                       © All rights reserved. Zend Technologies, Inc.
Where to get more on OOP?
   http://www.php.net/manual/en/language.oop5.php




                   © All rights reserved. Zend Technologies, Inc.
Class
      Think of a class as Source Code for object
      Defines object via properties and methods




Class keyword                                           Class Name


                                Class
                                Definition




                          © All rights reserved. Zend Technologies, Inc.
Hello World Class




               © All rights reserved. Zend Technologies, Inc.
Hello Class

   Output looks strangely familiar!




                       © All rights reserved. Zend Technologies, Inc.
Introduction to OO PHP
www.zend.com




 Components of an object




                © All rights reserved. Zend Technologies, Inc.
Question

            Why would you not just use functions that are already in
                                 global scope?
                                                          Problem
            There is no auto-loading mechanism for procedural code

            This means that ALL functions need to be loaded for EACH
                request
            Structure is defined 100% by naming convention

                                                           Answer
            Using classes to structure functionality means
                      1.      Only required functionality is compiled
                      2.      IFS access is minimized (this is good!)
   |
                                                                                                |
 23-
       Name of this section                   © All rights reserved. Zend Technologies, Inc.   26
Aug-
Class Properties
   Properties are also referred to as data
   Data representative of the class
   In our case, attributes about the customer
       Name
       Number
       Address




                       © All rights reserved. Zend Technologies, Inc.
Class Methods
   Methods are essentially functions in a class
   Provide database and some business logic
   In this example the method is display()




                                                                        Method




                       © All rights reserved. Zend Technologies, Inc.
Notes on objects

• Create Object:
  • $myObject = new Customer;




• Destroy Object
  • Unset $myObject;




                       © All rights reserved. Zend Technologies, Inc.
Introduction to OO PHP
www.zend.com




 Other OO stuff




                  © All rights reserved. Zend Technologies, Inc.
Magic methods
   Methods are functions
   Magic methods are like special reserved functions in PHP
   Must begin with double underscore _ _
   More info?
    http://www.php.net/manual/en/language.oop5.magic.php




                       © All rights reserved. Zend Technologies, Inc.
Magic Methods

       • Methods in objects that are called at special times
       • They always start with double underscore (__)
            __construct() *

            __destruct()

            __call()

            __get()

            __set()

            __sleep()

            __wakeup()

            __toString() *
   |
                                                                                 |
 23-
       Name of this section    © All rights reserved. Zend Technologies, Inc.   32
Aug-
Constructor
   _ _Construct()
       Think of it as *INZSR
       Executes code when object is instantiated




                           © All rights reserved. Zend Technologies, Inc.
Destructor
   _ _Destruct()
       Think of it as *INLR
       Executes code when object is destroyed




                           © All rights reserved. Zend Technologies, Inc.
Hello Class with Magic Methods




                                                               *INZSR



                                                               *INLR




              © All rights reserved. Zend Technologies, Inc.
Visibility
   Public
       Access to both inside and outside
   Private
       Access to only inside
   Protected
       Access only within the object itself, or other objects that
        extend the class.




                           © All rights reserved. Zend Technologies, Inc.
Visibility

       • Allows you to limit what parts of a class are available to
         other parts of your application



                              Application                    Extending Class        Class Internals

       Public

       Protected

       Private



   |
                                                                                                       |
 23-
       Name of this section        © All rights reserved. Zend Technologies, Inc.                     37
Aug-
Visibility




             © All rights reserved. Zend Technologies, Inc.
Introduction to OO PHP
www.zend.com




 I don„t know OO: Get Started NOW!!!




                © All rights reserved. Zend Technologies, Inc.
You don’t need to know OO to use it
   Using objects does not require OO knowledge
   Easy to weave into Procedural PHP applications
   http://www.phpclasses.org/




                           © All rights reserved. Zend Technologies, Inc.
41   Insert->Header & Footer   © All rights reserved. Zend Technologies, Inc.
42   Insert->Header & Footer   © All rights reserved. Zend Technologies, Inc.
43   Insert->Header & Footer   © All rights reserved. Zend Technologies, Inc.
Copy files to IFS




44   Insert->Header & Footer   © All rights reserved. Zend Technologies, Inc.
Test the example…




                                  My Code




45   Insert->Header & Footer   © All rights reserved. Zend Technologies, Inc.
Source Data Array Output




46   Insert->Header & Footer   © All rights reserved. Zend Technologies, Inc.
But I only want to check one email…




47   Insert->Header & Footer   © All rights reserved. Zend Technologies, Inc.
Code and output…




48   Insert->Header & Footer   © All rights reserved. Zend Technologies, Inc.
Where do I go next?




 49
Insert->Header & Footer   © All rights reserved. Zend Technologies, Inc.
Books!




     • Gutmans - PHP 5 Power Programming
     • White - PHP 5 in Practice
     • Schroeder/Olen – The IBM i
50                       © All rights reserved. Zend Technologies, Inc.
Build on OOP!




                                                                                PHP II
                                                                                Higher Structures!
                                                                                Call your account manager
                                                                                or go to the Zend website:
                                                                                http://shop.zend.com/en
                                                                                /php-training.html




51                             © All rights reserved. Zend Technologies, Inc.
     Insert->Header & Footer
Resources
     • Recorded Webinars
          http://www.zend.com/en/resources/webinars/i5-os



     • Zend Server for IBM i main page, link to downloads
          http://www.zend.com/en/products/server/zend-server-ibm-i



     • Zend Server manual:
          PDF: http://www.zend.com/topics/Zend-Server-5-for-IBMi-Reference-Manual.pdf

          Online: http://files.zend.com/help/Zend-Server-5/zend-
              server.htm#installation_guide.htm




54   Insert->Header & Footer              © All rights reserved. Zend Technologies, Inc.
Join us at ZendCon
The premier PHP conference!
October 17-19, 2011 – Santa Clara, CA


 Conference Highlights                                                       Conference Topics
 • Learn PHP best practices for architecture, design                         • Architecture & Design
   and development                                                           • Expanding Horizons
 • Technical sessions for all knowledge levels                               • IBM i
 • In-depth tutorials for advanced learning                                  • Lifecycle Best Practices
                                                                             • NoSQL / Alternative Stores / Search
 • PHP Certification courses and testing                                     • PHP Development
 • Exhibit hall showcasing the latest products                               • Server/Operations
 • Networking opportunities with peers and luminaries                        • SQL
                                                                             • Zend Framework
                                        www.zendcon.com
                                       © All rights reserved. Zend Technologies, Inc.
Q&A
                               www.zend.com
                        mike.p@zend.com

                Please fill out your
                Session Evaluation!
56   Insert->Header & Footer      © All rights reserved. Zend Technologies, Inc.
Webinar

      To watch the webinar please go to:
      http://www.zend.com/en/webinar/IBMi/70170000000bZBj-
      webinar-intro-to-oop-for-ibm-i-20110601.flv
      Or
      http://bit.ly/pFVlF1


      (a short registration is required)




Insert->Header & Footer            © All rights reserved. Zend Technologies, Inc.   57

Mais conteúdo relacionado

Mais de Zend by Rogue Wave Software

Develop web APIs in PHP using middleware with Expressive (Code Europe)
Develop web APIs in PHP using middleware with Expressive (Code Europe)Develop web APIs in PHP using middleware with Expressive (Code Europe)
Develop web APIs in PHP using middleware with Expressive (Code Europe)Zend by Rogue Wave Software
 
Fundamentals of performance tuning PHP on IBM i
Fundamentals of performance tuning PHP on IBM i  Fundamentals of performance tuning PHP on IBM i
Fundamentals of performance tuning PHP on IBM i Zend by Rogue Wave Software
 
Standard CMS on standard PHP Stack - Drupal and Zend Server
Standard CMS on standard PHP Stack - Drupal and Zend ServerStandard CMS on standard PHP Stack - Drupal and Zend Server
Standard CMS on standard PHP Stack - Drupal and Zend ServerZend by Rogue Wave Software
 

Mais de Zend by Rogue Wave Software (20)

Develop web APIs in PHP using middleware with Expressive (Code Europe)
Develop web APIs in PHP using middleware with Expressive (Code Europe)Develop web APIs in PHP using middleware with Expressive (Code Europe)
Develop web APIs in PHP using middleware with Expressive (Code Europe)
 
Middleware web APIs in PHP 7.x
Middleware web APIs in PHP 7.xMiddleware web APIs in PHP 7.x
Middleware web APIs in PHP 7.x
 
Ongoing management of your PHP 7 application
Ongoing management of your PHP 7 applicationOngoing management of your PHP 7 application
Ongoing management of your PHP 7 application
 
Developing web APIs using middleware in PHP 7
Developing web APIs using middleware in PHP 7Developing web APIs using middleware in PHP 7
Developing web APIs using middleware in PHP 7
 
The Docker development template for PHP
The Docker development template for PHPThe Docker development template for PHP
The Docker development template for PHP
 
The most exciting features of PHP 7.1
The most exciting features of PHP 7.1The most exciting features of PHP 7.1
The most exciting features of PHP 7.1
 
Unit testing for project managers
Unit testing for project managersUnit testing for project managers
Unit testing for project managers
 
The new features of PHP 7
The new features of PHP 7The new features of PHP 7
The new features of PHP 7
 
Deploying PHP apps on the cloud
Deploying PHP apps on the cloudDeploying PHP apps on the cloud
Deploying PHP apps on the cloud
 
Data is dead. Long live data!
Data is dead. Long live data! Data is dead. Long live data!
Data is dead. Long live data!
 
Optimizing performance
Optimizing performanceOptimizing performance
Optimizing performance
 
Resolving problems & high availability
Resolving problems & high availabilityResolving problems & high availability
Resolving problems & high availability
 
Developing apps faster
Developing apps fasterDeveloping apps faster
Developing apps faster
 
Keeping up with PHP
Keeping up with PHPKeeping up with PHP
Keeping up with PHP
 
Fundamentals of performance tuning PHP on IBM i
Fundamentals of performance tuning PHP on IBM i  Fundamentals of performance tuning PHP on IBM i
Fundamentals of performance tuning PHP on IBM i
 
Getting started with PHP on IBM i
Getting started with PHP on IBM iGetting started with PHP on IBM i
Getting started with PHP on IBM i
 
Continuous Delivery e-book
Continuous Delivery e-bookContinuous Delivery e-book
Continuous Delivery e-book
 
Standard CMS on standard PHP Stack - Drupal and Zend Server
Standard CMS on standard PHP Stack - Drupal and Zend ServerStandard CMS on standard PHP Stack - Drupal and Zend Server
Standard CMS on standard PHP Stack - Drupal and Zend Server
 
Dev & Prod - PHP Applications in the Cloud
Dev & Prod - PHP Applications in the CloudDev & Prod - PHP Applications in the Cloud
Dev & Prod - PHP Applications in the Cloud
 
The Truth about Lambdas and Closures in PHP
The Truth about Lambdas and Closures in PHPThe Truth about Lambdas and Closures in PHP
The Truth about Lambdas and Closures in PHP
 

Último

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 businesspanagenda
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
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.pdfsudhanshuwaghmare1
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
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...Orbitshub
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
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 TerraformAndrey Devyatkin
 
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...Zilliz
 
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 FMESafe Software
 
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 educationjfdjdjcjdnsjd
 
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 WorkerThousandEyes
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 

Último (20)

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
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
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...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
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
 
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...
 
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
 
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
 
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
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 

Introduction to OOP for IBM i Programmers

  • 1. Introduction to Object Oriented PHP Function Junction Mike Pavlak Solutions Consultant mike.p@zend.com (815) 722 3454 To watch the webinar please go to: http://www.zend.com/en/webinar/IBMi/70170000000bZBj-webinar-intro-to- oop-for-ibm-i-20110601.flv © All rights reserved. Zend Technologies, Inc.
  • 2. Foundations course starting next week! Call your account manager or go to the Zend website: http://shop.zend.com/en /php-training.html 2 © All rights reserved. Zend Technologies, Inc. Insert->Header & Footer
  • 3. Join us at ZendCon The premier PHP conference! October 17-19, 2011 – Santa Clara, CA Conference Highlights Conference Topics • Learn PHP best practices for architecture, design • Architecture & Design and development • Expanding Horizons • Technical sessions for all knowledge levels • IBM i • In-depth tutorials for advanced learning • Lifecycle Best Practices • NoSQL / Alternative Stores / Search • PHP Certification courses and testing • PHP Development • Exhibit hall showcasing the latest products • Server/Operations • Networking opportunities with peers and luminaries • SQL • Zend Framework www.zendcon.com © All rights reserved. Zend Technologies, Inc.
  • 4. Audience • New to PHP • New to Object Oriented Design • Open to new ideas and methods • This is not a DEEP DIVE  Relax and enjoy the ride! 4 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc.
  • 5. Agenda • Quick review of PHP basics • The class and its object • Components of an object Properties Methods • Other OO stuff • I don’t know OO: Get Started NOW! 5 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc.
  • 6. Roadmap to Expert PHP  RPG Green Screen  PHP Expert  Start somewhere! Here isn’t bad!  Path  Procedural PHP  OO PHP  Zend Framework (or another)  PHP Certification © All rights reserved. Zend Technologies, Inc.
  • 7. Questions? • Let’s keep it interactive! • Follow us! http://bit.ly/cjueZg (Zend Technologies or search for Zend) http://twitter.com/zend © All rights reserved. Zend Technologies, Inc.
  • 8. Introduction to OO PHP www.zend.com Quick review of PHP basics © All rights reserved. Zend Technologies, Inc.
  • 9. Variables <?php • Rules  Case senstive $field1 = 5; $field2 = 10;  Begin with $ $field3 = $field1 + $field2; • $thisIsMyVariable ?> • $__AnotherVariable • $ this is not a variable  Implicit casting  Can be re-typed (Dynamically Typed Language) • Constant – Variable that doesn’t change  Define(„TEACHER‟, “Mike Pavlak”); | 9 Modernizing legacy applications on i5 with PHP © All rights reserved. Zend Technologies, Inc. |
  • 10. Variables and their types • Scalar  Integer • -2,147,483,648 thru 2,147,483,647 • Supports decimal, octal and hex representation  Floating-Point • 1.7E-308 thru 1.7E+308 • 15 digits of decimal precision  Strings • Big. Really big. Too big to discuss!  Boolean • False is 0, 0.0, false keyword, empty string, object w/no values, null. All others are true • Object, array, null and resource | 10 Modernizing legacy applications on i5 with PHP © All rights reserved. Zend Technologies, Inc. |
  • 11. Variables…(cont.) • Scope  Global – Available everywhere but inside function (sort of)  Local – Available only in a function, destroyed at end  Static – Available only in a function, but remains • Arrays (three types)  Enumerated  Associative  Multi-dimensional | 11 Modernizing legacy applications on i5 with PHP © All rights reserved. Zend Technologies, Inc. |
  • 12. Functions  Functions come from 1 of 3 places  Built-in  Part of base PHP  Extensions  Components of modules like image functions in GD  User defined  You will create these!  You may have been using functions…  db2_connect()  print_r  strtoupper  Etc. | 12 © All rights reserved. Zend Technologies, Inc. 02/03
  • 13. What do functions look like? Function call has three major parts: Function Name - Required Parameters - Optional Return Value – Always returned, default null Return Function Name Parameters © All rights reserved. Zend Technologies, Inc.
  • 14. Scope • Variables have scope, much like RPG ILE • Function keeps its own set of variables • Global keyword can change all that (RPG III) • Better to pass, globals can‟t be trusted • Static variables • Persistence from call to call © All rights reserved. Zend Technologies, Inc.
  • 15. Parameters • Default • Assign value in interface • Pass by value • This is the default behavior • Pass by reference • This is done with & before the variable in the interface. • Variable number • func_get_args() • func_num_args() • func_get_arg(argument_#) © All rights reserved. Zend Technologies, Inc.
  • 16. Introduction to OO PHP www.zend.com The class and its object © All rights reserved. Zend Technologies, Inc.
  • 17. Concepts • Keywords class function static • Concepts Class Instance Magic Methods Visibility | | 23- Name of this section © All rights reserved. Zend Technologies, Inc. 17 Aug-
  • 18. RELAX!!! You may not be comfortable with the more modern structure Don’t feel like you NEED to follow it Take your time learning it. PHP lets you do this | | 23- Name of this section © All rights reserved. Zend Technologies, Inc. 18 Aug-
  • 19. Bare minimum • Keep library files out of the document root • Always name your PHP files .php • Keep data out of the document root • Do not deploy with a phpinfo.php file Do a Google search for “inurl:phpinfo.php” • Do not allow the web server to write to the document root • Always validate your input. Do a Google search for “inurl:page=home.php” | | 23- Name of this section © All rights reserved. Zend Technologies, Inc. 19 Aug-
  • 20. Object Model  Object is centered around data, not logic  Think about your RPG programs  You manipulate data.  Very few programs that have no data access  Object Definition:  Data structure with functions and variables local to each object.  Keep routines similar to data element together © All rights reserved. Zend Technologies, Inc.
  • 21. Where to get more on OOP?  http://www.php.net/manual/en/language.oop5.php © All rights reserved. Zend Technologies, Inc.
  • 22. Class  Think of a class as Source Code for object  Defines object via properties and methods Class keyword Class Name Class Definition © All rights reserved. Zend Technologies, Inc.
  • 23. Hello World Class © All rights reserved. Zend Technologies, Inc.
  • 24. Hello Class  Output looks strangely familiar! © All rights reserved. Zend Technologies, Inc.
  • 25. Introduction to OO PHP www.zend.com Components of an object © All rights reserved. Zend Technologies, Inc.
  • 26. Question Why would you not just use functions that are already in global scope? Problem There is no auto-loading mechanism for procedural code This means that ALL functions need to be loaded for EACH request Structure is defined 100% by naming convention Answer Using classes to structure functionality means 1. Only required functionality is compiled 2. IFS access is minimized (this is good!) | | 23- Name of this section © All rights reserved. Zend Technologies, Inc. 26 Aug-
  • 27. Class Properties  Properties are also referred to as data  Data representative of the class  In our case, attributes about the customer  Name  Number  Address © All rights reserved. Zend Technologies, Inc.
  • 28. Class Methods  Methods are essentially functions in a class  Provide database and some business logic  In this example the method is display() Method © All rights reserved. Zend Technologies, Inc.
  • 29. Notes on objects • Create Object: • $myObject = new Customer; • Destroy Object • Unset $myObject; © All rights reserved. Zend Technologies, Inc.
  • 30. Introduction to OO PHP www.zend.com Other OO stuff © All rights reserved. Zend Technologies, Inc.
  • 31. Magic methods  Methods are functions  Magic methods are like special reserved functions in PHP  Must begin with double underscore _ _  More info? http://www.php.net/manual/en/language.oop5.magic.php © All rights reserved. Zend Technologies, Inc.
  • 32. Magic Methods • Methods in objects that are called at special times • They always start with double underscore (__) __construct() * __destruct() __call() __get() __set() __sleep() __wakeup() __toString() * | | 23- Name of this section © All rights reserved. Zend Technologies, Inc. 32 Aug-
  • 33. Constructor  _ _Construct()  Think of it as *INZSR  Executes code when object is instantiated © All rights reserved. Zend Technologies, Inc.
  • 34. Destructor  _ _Destruct()  Think of it as *INLR  Executes code when object is destroyed © All rights reserved. Zend Technologies, Inc.
  • 35. Hello Class with Magic Methods *INZSR *INLR © All rights reserved. Zend Technologies, Inc.
  • 36. Visibility  Public  Access to both inside and outside  Private  Access to only inside  Protected  Access only within the object itself, or other objects that extend the class. © All rights reserved. Zend Technologies, Inc.
  • 37. Visibility • Allows you to limit what parts of a class are available to other parts of your application Application Extending Class Class Internals Public Protected Private | | 23- Name of this section © All rights reserved. Zend Technologies, Inc. 37 Aug-
  • 38. Visibility © All rights reserved. Zend Technologies, Inc.
  • 39. Introduction to OO PHP www.zend.com I don„t know OO: Get Started NOW!!! © All rights reserved. Zend Technologies, Inc.
  • 40. You don’t need to know OO to use it  Using objects does not require OO knowledge  Easy to weave into Procedural PHP applications  http://www.phpclasses.org/ © All rights reserved. Zend Technologies, Inc.
  • 41. 41 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc.
  • 42. 42 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc.
  • 43. 43 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc.
  • 44. Copy files to IFS 44 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc.
  • 45. Test the example… My Code 45 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc.
  • 46. Source Data Array Output 46 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc.
  • 47. But I only want to check one email… 47 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc.
  • 48. Code and output… 48 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc.
  • 49. Where do I go next? 49 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc.
  • 50. Books! • Gutmans - PHP 5 Power Programming • White - PHP 5 in Practice • Schroeder/Olen – The IBM i 50 © All rights reserved. Zend Technologies, Inc.
  • 51. Build on OOP! PHP II Higher Structures! Call your account manager or go to the Zend website: http://shop.zend.com/en /php-training.html 51 © All rights reserved. Zend Technologies, Inc. Insert->Header & Footer
  • 52. Resources • Recorded Webinars http://www.zend.com/en/resources/webinars/i5-os • Zend Server for IBM i main page, link to downloads http://www.zend.com/en/products/server/zend-server-ibm-i • Zend Server manual: PDF: http://www.zend.com/topics/Zend-Server-5-for-IBMi-Reference-Manual.pdf Online: http://files.zend.com/help/Zend-Server-5/zend- server.htm#installation_guide.htm 54 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc.
  • 53. Join us at ZendCon The premier PHP conference! October 17-19, 2011 – Santa Clara, CA Conference Highlights Conference Topics • Learn PHP best practices for architecture, design • Architecture & Design and development • Expanding Horizons • Technical sessions for all knowledge levels • IBM i • In-depth tutorials for advanced learning • Lifecycle Best Practices • NoSQL / Alternative Stores / Search • PHP Certification courses and testing • PHP Development • Exhibit hall showcasing the latest products • Server/Operations • Networking opportunities with peers and luminaries • SQL • Zend Framework www.zendcon.com © All rights reserved. Zend Technologies, Inc.
  • 54. Q&A www.zend.com mike.p@zend.com Please fill out your Session Evaluation! 56 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc.
  • 55. Webinar To watch the webinar please go to: http://www.zend.com/en/webinar/IBMi/70170000000bZBj- webinar-intro-to-oop-for-ibm-i-20110601.flv Or http://bit.ly/pFVlF1 (a short registration is required) Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. 57