Classes in PHP Web Engineering. What is Class? A class is a collection of variables and functions working with these variables. Variables are defined.

Slides:



Advertisements
Similar presentations
Final and Abstract Classes
Advertisements

Pemrograman Web Object Oriented Programming in PHP 5.
Object Oriented Programming in PHP 5
L3:CSC © Dr. Basheer M. Nasef Lecture #3 By Dr. Basheer M. Nasef.
Object-Oriented PHP (1)
Week 4 Recap CSE 115 Spring Formal Parameter Lists Comma-separated list of formal parameters Formal parameters are listed giving the type of the.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Classes and Objects  A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Introduction to Java Programming, 4E Y. Daniel Liang.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Writing a Class (defining a data-type). Create a new project : Project (uncheck the “Create Main Class”)
PHP Programming with MySQL Slide 11-1 CHAPTER 11 Developing Object-Oriented PHP.
PHP Workshop ‹#› PHP Classes and Object Orientation.
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Objectives In this chapter, you will:
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
ClassesPHPMay-2007 : [‹#›] PHP Classes and Object Orientation.
Object-Oriented PHP (Chapter 6).
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.
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 07.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
Chapter 8 Objects and Classes Object Oriented programming Instructor: Dr. Essam H. Houssein.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)OO PHP PHP Classes and Object Orientation.
JavaScript, Fourth Edition
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
1 CSC241: Object Oriented Programming Lecture No 02.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Objects and Classes.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
CS 139 Objects Based on a lecture by Dr. Farzana Rahman Assistant Professor Department of Computer Science.
Classes, Interfaces and Packages
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.
Chapter 10 Developing Object-Oriented PHP. 2 Objectives In this chapter, you will: Study object-oriented programming concepts Use objects in PHP scripts.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Non-Static Classes What is the Object of this lecture?
 We have created our two separate 'person' objects, we can set their properties using the methods (the setters) we created.  class person {  var $name;
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 7: Introduction to Object- Oriented Programming in Python – Exercises Xiang Lian The University of.
INTRODUCTION TO CLASSES & OBJECTS CREATING CLASSES USING C#
A Simple Object Oriented Program public class Simple { public static void main (String [] args) { System.out.println(“howdy”); } System.out is an object.
UNIT-IV WT. Why use classes and objects? PHP is a primarily procedural language small programs are easily written without adding any classes or objects.
Classes & Objects There are two main programming paradigms: Procedural Object-Oriented Up to now, everything we have done has been procedural.
Objects as a programming concept
2.7 Inheritance Types of inheritance
PHP Classes and Objects
Chapter 11 Developing Object-Oriented PHP PHP Programming with MySQL Revised by A. Philipp – Spring 2010 (Rev SP’11)
HIGHLEVEL REVIEW Chapter 9 Objects and Classes
Object-oriented Design in Processing
Week 3 Object-based Programming: Classes and Objects
CSCI 297 Scripting Languages Day Seven
Chapter 8 Objects and Classes
CS100J Lecture 8 Previous Lecture This Lecture Programming Concepts
Object-oriented Design in Processing
Object-Oriented Programming in PHP
Assessment – Java Basics: Part 1
Software Engineering for Internet Applications
Chapter 6 Objects and Classes
CIS 199 Final Review.
Chapter 8 Objects and Classes
Object-oriented Design in Processing
Final and Abstract Classes
Classes and Objects Imran Rashid CTO at ManiWeber Technologies.
Object-oriented Design in Processing
[Robert W. Sebesta, “Programming the World Wide Web
Presentation transcript:

Classes in PHP Web Engineering

What is Class? A class is a collection of variables and functions working with these variables. Variables are defined by var and functions by function. A class is defined using the following syntax: <?php class test { function test123() { echo “OK”; } } ?>

Class In PHP Concept of class ( or basic object oriented structure) introduced from php4. But complete coverage of class like access modifier or interface is introduced from php5. Creating class is very easy in php. You can create class with help of using class keywordin php.

Example – Define Class class myOwnClass { //variables or properties of the class var $variable1; var $variable2; //Function of class function mergeVariable() { return $this->variable1. $this->variable2; } } $this variable is used to make the object can get information about itself. "$this->variable1" indicates / makes to be called the “variable1" property of the current object of this class. When accessing properties, you need only one $. The syntax is $obj->property

What is Object Classes are useless without objects. Object is an instance of your class. If you have class then you need to create object of the class to solve your problem using class. You can create object of your class by using new keyword. $objClass = new myOwnClass; OR $objClass = new myOwnClass(); NOTE: You can create an object of class with or without ().

Example class MyLock { var $isLocked = false; function unlock() { $this->isLocked = false; echo 'You unlocked the Lock'; } function lock() { $this->isLocked = true; echo 'You locked the Lock'; } $mylockobj= new MyLock; $mylockobj->unlock(); // You unlocked the Lock (Call Function of Class)

Constructor Function The Constructor method is a special type of function called __construct within the class body. To declare /create a constructor method, use the __construct name (begins with two underscore "__"). This method is always "public" even if this attribute is not specified. The difference from the other functions is that a constructor method is automatically invoked when an object is created. NOTE: if you have __construct then it will be the first preference. If __construct function is not present then it will search for the function with the same name of class.

<?php class MyDestructableClass { Var $name; function __construct() { print "In constructor\n"; $this->name = “I m in constructor"; } function __destruct() { print "Destroying ". $this->name. "\n"; } } $obj = new MyDestructableClass; ?>

class Door { private $lock; private $connectsTo; public function __construct() { $this->lock = “Yes”; $this->connectsTo = 'bedroom'; } public function open() { Echo “Your door lock value is “.$this->lock; echo 'You opened the Door : ', $this->connectsTo; } $myDoor = new Door(); $myDoor->open();