PHP extras Some advance elements not required in the project.

Slides:



Advertisements
Similar presentations
PHP functions What are Functions? A function structure:
Advertisements

Recursion 2014 Spring CS32 Discussion Jungseock Joo.
Pemrograman Web Object Oriented Programming in PHP 5.
Object Oriented Programming in PHP 5
Bayu Priyambadha, S.Kom.  Final Keyword  Class Abstraction  Object Interfaces.
C++ Programming Languages
Data Structures Lecture 2 Fang Yu Department of Management Information Systems National Chengchi University Fall 2011.
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
4/29/20151 Java Exceptions. 4/29/20152 Overview An exception is an unusual circumstance, such as an error condition, that must be handled in a non-standard.
Written by: Dr. JJ Shepherd
Exception Handling The purpose of exception handling is to permit the program to catch and handle errors rather than letting the error occur and suffer.
1 Lecture 11 Interfaces and Exception Handling from Chapters 9 and 10.
 Stands for "Object-Oriented Programming." OOP refers to a programming methodology based on objects, instead of just functions and procedures. These objects.
Object-Oriented PHP (1)
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Object-Oriented Design. Method for designing computer programs Consider “objects” interacting in the program –Example: a zoo.
Abstract Data Types and Encapsulation Concepts
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
12.1 Exceptions The limitations of traditional methods of exception handling Error conditions are a certainty in programming Programmers make.
Nikolay Kostov Telerik Corporation
Java Methods By J. W. Rider. Java Methods Modularity Declaring methods –Header, signature, prototype Static Void Local variables –this Return Reentrancy.
2.5 OOP Principles Part 1 academy.zariba.com 1. Lecture Content 1.Fundamental Principles of OOP 2.Inheritance 3.Abstraction 4.Encapsulation 2.
Throwing and Catching Exceptions Tran Anh Tuan Edit from Telerik Software Academy
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
BASE CLASSES AND INHERITANCE CHAPTER 4. Engineer Class.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Object Oriented Programming Elhanan Borenstein Lecture #4.
Svetlin Nakov Technical Trainer Software University Object-Oriented Programming in PHP Classes, Class Members, OOP Principles.
Martin Kruliš This is an Object Oriented system. If we change something, the users object by Martin Kruliš (v1.0)1.
Introduction to Java Prepared by: Ahmed Hefny. Outline Classes Access Levels Member Initialization Inheritance and Polymorphism Interfaces Inner Classes.
OOP with PHP Roman Bednarik
Object Oriented Programming in PHP. Topics Quick OOP Review Classes Magic Methods Static Methods Inheritance Exceptions Interfaces Operators Type Hinting.
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 07.
Inheritance in the Java programming language J. W. Rider.
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
CSC 270 – Survey of Programming Languages C++ Lecture 6 – Exceptions.
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Classes, Interfaces and Packages
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
CIS 200 Test 01 Review. Built-In Types Properties  Exposed “Variables” or accessible values of an object  Can have access controlled via scope modifiers.
Intermediate PHP (4) Object-Oriented PHP (2). Object-oriented concepts Classes, attributes and operations Class attributes Per-class constants Class method.
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.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
OOP Basics Classes & Methods (c) IDMS/SQL News
PHP Exception Handling How to handle and create user-defined exceptions Mario Peshev Technical Trainer Software University
Chapter 9: Continuing Classes By Matt Hirsch. Table Of Contents 1.Static Fields and Methods 2.Inheritance I. Recycle Code with Inheritance II. Overriding.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
Advanced Programming Practice Questions Advanced Programming. All slides copyright: Chetan Arora.
Inheritance a subclass extends the functionality of a superclass a subclass inherits all the functionality of a superclass don't reinvent the wheel – "stand.
Chapter 2 Objects and Classes
Written by: Dr. JJ Shepherd
Lecture 12 Inheritance.
Objects as a programming concept
CIS 200 Test 01 Review.
Object-Oriented Programming (OOP) Lecture No. 45
PHP Classes and Objects
Object-Orientated Programming
Chapter 2 Objects and Classes
Java Programming Language
Chapter 12 Exception Handling and Text IO
Advanced Java Programming
CSCI 297 Scripting Languages Day Seven
Object-Oriented Programming in PHP
Software Engineering for Internet Applications
OOP Aga private institute for computer science 5th grade
Classes and Objects Imran Rashid CTO at ManiWeber Technologies.
Presentation transcript:

PHP extras Some advance elements not required in the project

Error handling So far: – die ($status) – exit ($status) - Terminates execution of the script

Error handling Try, catch, throw try { $a=$_POST[“val1”]/$_POST[“val2”]; } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(); throw $e; // route it further }

Classes class FirstClass { public $info = 4; // property public function displayInfo() // method { echo $this->info; } } usage: $a = new FirstClass(); $a->displayInfo(); Visibility: public protected private

Inheritance class SecondClass extends FirstClass { public function displayHalfInfo() // method { echo ($this->info/2); } }

Inheritance class GenClass { public $salary= 40000; public function displayPaidSalary() { echo $this->salary; } } class EstClass extends GenClass { public function displayPaidSalary() { echo $this->salary*0.78; } } redefines the function $a=new GenClass(); $b=new EstClass(); // shows $a->displaySalary(); // shows 7800 $b->displaySalary();

Constructor class FClass { function __construct() { echo “first class constructor"; } function __destruct() { print "Destroying first class"; } } class SClass extends FClass { protected $val=0; function __construct() { parent::__construct(); print “second class constructor\n"; } function __construct($initVal){ $this->$val=$initval; } } Release resources and notify other objects if needed Acquire resources and set initial values Parent construtor is called directly

Static (shared) class General { public static $my_shared = 55; public static function StaticMethod() { //... } } echo General::my_shared; echo General::StaticMethod;

Interface interface iOutput { public function getHtml(); } class Student implement iOutput { private $mName=“Name1”; private $mCode=“098132”; public function getHtml() { echo “ $mCode /”; echo “ $mName ”; } class Teacher implement iOutput { private $mName=“Name1”; private $mPosition=“Prof”; public function getHtml() { echo “$nPosition $mName ”; } $arr[0]=new Student(); $arr[1]=new Teacher(); foreach($arr as $value) $value->getHtml();

Abstraction abstract class AbstractClass { abstract protected function getValue(); public function printOut() { print $this->getValue(). "\n"; } } class ConcreteClass1 extends AbstractClass { protected function getValue() { return "ConcreteClass1"; } } class ConcreteClass2 extends AbstractClass { public function getValue() { return "ConcreteClass2"; } }

Namespaces A possibility to encapsulate and divide similar concepts by the area of usage. For example there could be an “operation” concept, which means one in math and another in medicine namespace CompanyName\Finance; class Account { static function getHtml() {} } namespace CompanyName\Security; class Account { static function getHtml() {} }

Namespaces: usage calling echo CompanyName\Finance\Account::getHtml(); echo CompanyName\Security\Account::getHtml(); calling use CompanyName\Finance; echo Account::getHtml(); namespace CompanyName\Finance; class Account { static function getHtml() {} } namespace CompanyName\Security; class Account { static function getHtml() {} }