 First thing we need to do is create two PHP pages:  index.php  class_lib.php  OOP is all about creating modular code, so our object oriented PHP.

Slides:



Advertisements
Similar presentations
1 Storage Duration and Scope –Local and global variables Storage classes –automatic, static, external, register Todays Material.
Advertisements

General OO Concepts Objectives For Today: Discuss the benefits of OO Programming Inheritance and Aggregation Abstract Classes Encapsulation Introduce Visual.
MWD1001 Website Production Using JavaScript with Forms.
Mark Dixon Page 1 23 – Object Oriented Programming in PhP.
1 l Inheritance Basics l Programming with Inheritance l Dynamic Binding and Polymorphism Inheritance.
PHP Functions / Modularity
Objectives Using functions to organize PHP code
PACS – 10/19/131 Object-Oriented Programming “Object-oriented programming opens the door to cleaner designs, easier maintenance, and greater code reuseability.”
CS 330 Programming Languages 10 / 14 / 2008 Instructor: Michael Eckmann.
SERVER web page repository WEB PAGE instructions stores information and instructions BROWSER retrieves web page and follows instructions Server Web Server.
Object-Oriented PHP (1)
PHP Workshop ‹#› PHP Classes and Object Orientation.
Guide to Programming with Python
What is Object-Oriented Programming?. Objects – Variables and Logic inside "Objects", not standalone code – Objects contain related variables and functions.
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
Chapter 4 Objects and Classes.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Functions & Objects IDIA 618 Spring 2012 Bridget M. Blodgett.
NetTech Solutions Working with Web Elements Lesson 6.
Tutorial 2 Variables and Objects. Working with Variables and Objects Variables (or identifiers) –Values stored in computer memory locations –Value can.
Object-Oriented Programming (OOP). Implementing an OOD in Java Each class is stored in a separate file. All files must be stored in the same package.
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
ClassesPHPMay-2007 : [‹#›] PHP Classes and Object Orientation.
OOP IN PHP `Object Oriented Programming in any language is the use of objects to represent functional parts of an application and real life entities. For.
Object Oriented Programming in PHP. List of Items of Interest What is a Class What is an Object What is a Singleton Multiple Objects, How to store. Advantages.
Chapter 2 Functions and Control Structures PHP Programming with MySQL 2 nd Edition.
COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.
PHP Constructs Advance Database Management Systems Lab no.3.
Desktop Publishing Formatting Pages. Topics to Study Page Setup Apply Built-in options Use Layout Guides Color- Coded Guides Insert Page numbers Create.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)OO PHP PHP Classes and Object Orientation.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC PROGRAMMING FUNDAMENTALS Bilal Munir Mughal 1 Chapter-8.
Defining Classes I Part A. Class definitions OOP is the dominant programming methodology in use today. OOP is the dominant programming methodology in.
Overview The Basics – Python classes and objects Procedural vs OO Programming Entity modelling Operations / methods Program flow OOP Concepts and user-defined.
JavaScript, Fourth Edition
ActionScript: For Loops, While Loops, Concatenation and Arrays MMP 220 Multimedia Programming This material was prepared for students in MMP220 Multimedia.
PHP OOP WEB Technologies : PHP Programming Language.
DISTRIBUTIVE PROPERTY. When no addition or subtraction sign separates a constant or variable next to a parentheses, it implies multiplication.
 A PHP script can be placed anywhere in the document.  A PHP script starts with  The default file extension for PHP files is ".php".  A PHP file normally.
TeachJava! 2003 Corky Cartwright Dung Nguyen Stephen Wong Charlie Reis, James Hsia, Peter Centgraf.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Introduction to Functions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
Classes in PHP Web Engineering. What is Class? A class is a collection of variables and functions working with these variables. Variables are defined.
21. PHP Classes To define a class, use the keyword class followed by the name and a block with the properties and method definitions Properties are declared.
 We have created our two separate 'person' objects, we can set their properties using the methods (the setters) we created.  class person {  var $name;
PHP Functions / Modularity Dr. Charles Severance
Notes 3.4 – SOLVING MULTI-STEP INEQUALITIES
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
Introduction to Arrays. Learning Objectives By the end of this lecture, you should be able to: – Understand what an array is – Know how to create an array.
Generic Programming and Library Design Brian Bartman
 The real power of PHP comes from its functions; it has more than 1000 built-in functions.  PHP User Defined Functions  Besides the built-in PHP functions,
CPS120: Introduction to Computer Science Lecture 16A Object-Oriented Concepts.
ITM 3521 ITM 352 Functions. ITM 3522 Functions  A function is a named block of code (i.e. within {}'s) that performs a specific set of statements  It.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Classes C++ representation of an object
CHAPTER 4 CLIENT SIDE SCRIPTING PART 3 OF 3
Advance OOP in PHP.
Scope, Objects, Strings, Numbers
Unit 4 – Functions and Include Files
PHP.
Tonga Institute of Higher Education
For this assignment, copy and past the XHTML to a notepad file with the .html extension. Then add the code I ask for to complete the problems.
Multiplying monomial with binomial
Classes C++ representation of an object
Object-Oriented PHP (1)
Web Programming and Design
ITM 352 Functions.
Presentation transcript:

 First thing we need to do is create two PHP pages:  index.php  class_lib.php  OOP is all about creating modular code, so our object oriented PHP code will be  contained in dedicated files that we will then insert into our normal PHP page using  php 'includes'. In this case all our OO PHP code will be in the PHP file:  class_lib.php

 You define your own class by starting with the keyword 'class' followed by the name  you want to give your new class.  <?php  class person {  }

 One of the big differences between functions and classes is that a class contains both data  (variables) and functions that form a package called an: 'object'. When you create a  variable inside a class, it is called a 'property'.  <?php  class person {  var $name; }}  Note: The data/variables inside a class (var $name;) are called 'properties'.

 In the same way that variables get a different name when created inside a class(they are called: properties,) functions also referred to by a different name when created inside a class they are called 'methods'.  A classes' methods are used to manipulate its' own data / properties.

 <?php  class person {  var $name;  function set_name($new_name) {  $this->name = $new_name; }}  function get_name() {  return $this->name; } }}

 We have created two interesting functions/methods:  get_name() and set_name().  STEP 6: The '$this' variable  The $this is a built-in variable (built into all objects) which points to the current  object. Or in other words, $this is a special self-referencing variable.

 You use $this to access properties and to call other methods of the current class.  function get_name() {  return $this->name;  }

 You would never create your PHP classes directly inside your main php pages.  Instead, it is always best practice to create separate php pages that only contain  your classes.  Then you would access your php objects/classes by including them in your main php pages with either a php 'include' or 'require'.

  OOP in PHP 

 <?php  $stefan = new person();  ?> 

 The variable $stefan becomes a handle/reference to our newly created person object.  STEP 9: The 'new' keyword  To create an object out of a class, you need to use the 'new' keyword.  When creating/instantiating a class, you can optionally add brackets to the class name.

 As we did in the example below. To be clear, you can see in the code below how we can create multiple objects from the same class.   <?php  $stefan = new person();  $jimmy = new person();  ?> 