This document provides an overview of object-oriented programming concepts in PHP, including defining classes, creating objects, inheritance, and introspection methods. It also covers PHP sessions and using session variables to maintain data across multiple pages. Key topics include defining classes with properties and methods, creating object instances, accessing object properties and methods, constructors and destructors, inheritance between classes, and functions for examining classes and objects.
This PPT gives information about:
Advanced Theories
Inheriting Classes
Inheriting Constructors and Destructors
Overriding Methods
Access Control
Using the Scope Resolution Operator
Creating Static Members
Abstract Classes and Methods
This PPT gives information about:
Advanced Theories
Inheriting Classes
Inheriting Constructors and Destructors
Overriding Methods
Access Control
Using the Scope Resolution Operator
Creating Static Members
Abstract Classes and Methods
If you are new to programing in general OR if you started programing in php before Object-Oriented Programming was even available, this presentation is designed to help you get up to speed on Object-Oriented terminology and give you practical skills as well as resources to continue learning.
This ppt gives information about:
1. OOPs Theory
2. Defining a Class
3. Creating an Object
4. The $this Attribute
5. Creating Constructors
6. Creating Destructors
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAMaulik Borsaniya
Classes and Object-oriented Programming:
Classes: Creating a Class, The Self Variable, Constructor, Types of Variables, Namespaces, Types of Methods (Instance Methods, Class Methods, Static Methods), Passing Members of One Class to Another Class, Inner Classes
Inheritance and Polymorphism: Constructors in Inheritance, Overriding Super Class Constructors and Methods, The super() Method, Types of Inheritance, Single Inheritance, Multiple Inheritance, Method Resolution Order (MRO), Polymorphism, Duck Typing Philosophy of Python, Operator Overloading, Method Overloading, Method Overriding
Abstract Classes and Interfaces: Abstract Method and Abstract Class, Interfaces in Python, Abstract Classes vs. Interfaces,
Drupal Entities - Emerging Patterns of UsageRonald Ashri
Entities are a powerful architectural approach and tool introduced in Drupal 7 - in this presentation I explain what they are and how they can be used with references to examples of how entities are used already.
Presentation I gave at the Berkeley Drupal Users Group on February 27, 2012 covering entities in Drupal 7 including entity types, bundles, fields, nodes, the Entity API and the Schema API. I use TextbookMadness.com as an example of how to leverage entities.
Click on my name to find a newer (better!) version of these slides.
Keynote by Fabrizio Capobianco of Funambol at the World Computer Congress 2008. The talk is entitled 'A Successful Business Model for Open Source Systems'
If you are new to programing in general OR if you started programing in php before Object-Oriented Programming was even available, this presentation is designed to help you get up to speed on Object-Oriented terminology and give you practical skills as well as resources to continue learning.
This ppt gives information about:
1. OOPs Theory
2. Defining a Class
3. Creating an Object
4. The $this Attribute
5. Creating Constructors
6. Creating Destructors
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAMaulik Borsaniya
Classes and Object-oriented Programming:
Classes: Creating a Class, The Self Variable, Constructor, Types of Variables, Namespaces, Types of Methods (Instance Methods, Class Methods, Static Methods), Passing Members of One Class to Another Class, Inner Classes
Inheritance and Polymorphism: Constructors in Inheritance, Overriding Super Class Constructors and Methods, The super() Method, Types of Inheritance, Single Inheritance, Multiple Inheritance, Method Resolution Order (MRO), Polymorphism, Duck Typing Philosophy of Python, Operator Overloading, Method Overloading, Method Overriding
Abstract Classes and Interfaces: Abstract Method and Abstract Class, Interfaces in Python, Abstract Classes vs. Interfaces,
Drupal Entities - Emerging Patterns of UsageRonald Ashri
Entities are a powerful architectural approach and tool introduced in Drupal 7 - in this presentation I explain what they are and how they can be used with references to examples of how entities are used already.
Presentation I gave at the Berkeley Drupal Users Group on February 27, 2012 covering entities in Drupal 7 including entity types, bundles, fields, nodes, the Entity API and the Schema API. I use TextbookMadness.com as an example of how to leverage entities.
Click on my name to find a newer (better!) version of these slides.
Keynote by Fabrizio Capobianco of Funambol at the World Computer Congress 2008. The talk is entitled 'A Successful Business Model for Open Source Systems'
CRO Tesla Tour
Innovative Tourism
www.e-tesla.org
Zavičajni muzej Ozalj/ Grad Ozalj, TZ Karlovac, Free Dance, Slobodna škola, ZPC
Autori projekta : Novi svijet- KulturA Urbani
kontakt: urbanipress@gmail.com
Climbing Off The Ladder, Before We Fall OffC4Media
Video and slides synchronized, mp3 and slide download available at URL http://bit.ly/1ow1OJN.
Chris Angove outlines the challenges having only a linear growth option, the organization of Spotify and the attempt to provide non-linear options to improve happiness and retention within the team. Filmed at qconnewyork.com.
Chris Angove is a Chapter Lead at Spotify in New York City, where he works with a team of backend engineers on the services powering the music streaming service. Since graduating from the University of Michigan he has spent over a decade working with various teams to make high quality software from network simulation tools, education software and now in the music streaming sphere.
Penn State RCC has been a CUDA research center for the last year; this talk provides success stories and challenges. GPU case studies are given, including algorithm details and performance results.
The changing landscape of recruiting and admissions requires constant innovation. This panel will discuss some of the ways that graduate admissions offices are using online tools for recruiting and conversion.
Abstraction, Encapsulation, Polymorphism, and Interfaces: whether you’ve been programming in PHP for years or are just starting your journey, these terms can be overwhelming even on a good day. Variables, conditionals, those all make sense. But this whole Object-Oriented thing is WAY more complicated. Not only that, people that already understand it act like it’s so easy and they talk right over the simple questions and never explain the basic concepts in a way that actually makes sense. In this session we’ll take you through real life examples of Object-Oriented terminology in a way that will make sense of all the mumbo jumbo and allow you to utilizing OOP immediately.
Object oriented programming assume everything as an object
Class − This is a programmer-defined data type, which includes local functions as well as local data.
Object − An individual instance of the data structure defined by a class.
Member Variable − These are the variables defined inside a class.
Member function − These are the function defined inside a class and are used to access object data.
Inheritance − When a class is defined by inheriting existing function of a parent class then it is called inheritance.
Parent class − A class that is inherited from by another class. This is also called a base class or super class.
Child Class − A class that inherits from another class. This is also called a subclass or derived class.
Polymorphism − This is an object oriented concept where same function can be used for different purposes. For example function name will remain same but it take different number of arguments and can do different task.
Data Abstraction − Any representation of data in which the implementation details are hidden (abstracted).
Encapsulation − refers to a concept where we encapsulate all the data and member functions together to form an object.
Constructor − refers to a special type of function which will be called automatically whenever there is an object formation from a class.
Destructor − refers to a special type of function which will be called automatically whenever an object is deleted or goes out of scope.
....
4. Use the AM for posting within scientific collaboration networks (SCNs). For a detailed description of our policy on posting to SCNs, please see our Web Posting Guidelines (https://publishing.aip.org/authors/web-posting-guidelines).
5. Reprint the Version of Record (VOR) in print collections written by the Author, or in the Author’s thesis or dissertation. It is understood and agreed that the thesis or dissertation may be made available electronically on the university’s site or in its repository and that copies may be offered for sale on demand.
6. Reproduce copies of the VOR for courses taught by the Author or offered at the institution where the Author is employed, provided no fee is charged for access to the Work.
7. Use the VOR for internal training and noncommercial business purposes by the Author’s employer.
8. Use the VOR in oral presentations made by the Author, such as at conferences, meetings, seminars, etc., provided those receiving copies are informed that they may not further copy or distribute the Work.
9. Distribute the VOR to colleagues for noncommercial scholarly use, provided those receiving copies are informed that they may not further copy or distribute the Work.
10. Post the VOR to their personal web page or their employer’s web page 12 months after publication by AIP Publishing.
11. Deposit the VOR in an institutional or funder-designated repository 12 months after publication by AIP Publishing.
12. Update a prior posting with the VOR on a noncommercial server such as arXiv, 12 months after publication by AIP Publishing.
Author Warranties
Each Author and Copyright Owner represents and warrants to AIP Publishing the following:
1. The Work is the original independent creation of each Author and does not infringe any copyright or violate any other right of any third party.
2. The Work has not been previously published and is not being considered for publication elsewhere in any form, except as a preprint on a noncommercial server such as arXiv, or in a thesis or dissertation.
3. Written permission has been obtained for any material used from other sources and copies of the permission grants have been supplied to AIP Publishing to be included in the manuscript file.
4. All third-party material for which permission has been obtained has been properly credited within the manuscript.
5. In the event that the Author is subject to university open access policies or other institutional restrictions that conflict with any of the rights or provisions of this License, such Author has obtained the necessary waiver from his or her university or institution.
This License must be signed by the Author(s) and, in the case of a Work Made for Hire, also by the Copyright Owners. One Author/Copyright Owner may sign on behalf of all the contributors/owners only if they all have authorized the signing, approved of the License, and agreed to be bound by it. The signing Author and, in the case of a Work Made for Hire, the signing Copyright Owne
The recent Project of the Month on SourceForge, XOOPS (http://www.xoops.org) was designed from the very beginning as an object-oriented CMS, which is even reflected in its name: eXtensible Object Oriented Portal System. Michael will present the OOP oriented architecture of XOOPS, and show how OOP makes development of XOOPS modules easy and fun, promotes reuse of code, while keeping GUI consistent across all modules.
Demystifying Object-Oriented Programming - PHP UK Conference 2017Alena Holligan
Abstraction, Encapsulation, Polymorphism, and Interfaces: whether you’ve been programming in PHP for years or are just starting your journey, these terms can be overwhelming even on a good day. Variables, conditionals, those all make sense. But this whole Object-Oriented thing is WAY more complicated. Not only that, people that already understand it act like it’s so easy and they talk right over the simple questions and never explain the basic concepts in a way that actually makes sense. In this session we’ll take you through real life examples of Object-Oriented terminology in a way that will make sense of all the mumbo jumbo and allow you to utilizing OOP immediately.
Abstraction, encapsulation, polymorphism, and interfaces: whether you've been programming in PHP for years or are just starting your journey, these terms can be overwhelming even on a good day. Variables, conditionals, those all make sense. But this whole object-oriented thing is way more complicated. Not only that, people that already understand it, act like it's so easy and they talk right over the simple questions and never explain the basic concepts in a way that actually makes sense. In this session, we'll take you through real-life examples of object-oriented terminology in a way that will make sense of all the mumbo jumbo and allow you to utilize object-oriented programming (OOP) immediately.
Demystifying Object-Oriented Programming - Lone Star PHPAlena Holligan
Abstraction, Encapsulation, Polymorphism, and Interfaces: whether you’ve been programming in PHP for years or are just starting your journey, these terms can be overwhelming even on a good day. Variables, conditionals, those all make sense. But this whole Object-Oriented thing is WAY more complicated. Not only that, people that already understand it act like it’s so easy and they talk right over the simple questions and never explain the basic concepts in a way that actually makes sense. In this session we’ll take you through real life examples of Object-Oriented terminology in a way that will make sense of all the mumbo jumbo and allow you to utilizing OOP immediately.
Abstraction, Encapsulation, Polymorphism, and Interfaces: whether you’ve been programming in PHP for years or are just starting your journey, these terms can be overwhelming even on a good day. Variables, conditionals, those all make sense. But this whole Object-Oriented thing is WAY more complicated. Not only that, people that already understand it act like it’s so easy and they talk right over the simple questions and never explain the basic concepts in a way that actually makes sense. In this session we’ll take you through real life examples of Object-Oriented terminology in a way that will make sense of all the mumbo jumbo and allow you to utilizing OOP immediately.
"Impact of front-end architecture on development cost", Viktor TurskyiFwdays
I have heard many times that architecture is not important for the front-end. Also, many times I have seen how developers implement features on the front-end just following the standard rules for a framework and think that this is enough to successfully launch the project, and then the project fails. How to prevent this and what approach to choose? I have launched dozens of complex projects and during the talk we will analyze which approaches have worked for me and which have not.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
Here is something new! In our next Connector Corner webinar, we will demonstrate how you can use a single workflow to:
Create a campaign using Mailchimp with merge tags/fields
Send an interactive Slack channel message (using buttons)
Have the message received by managers and peers along with a test email for review
But there’s more:
In a second workflow supporting the same use case, you’ll see:
Your campaign sent to target colleagues for approval
If the “Approve” button is clicked, a Jira/Zendesk ticket is created for the marketing design team
But—if the “Reject” button is pushed, colleagues will be alerted via Slack message
Join us to learn more about this new, human-in-the-loop capability, brought to you by Integration Service connectors.
And...
Speakers:
Akshay Agnihotri, Product Manager
Charlie Greenberg, Host
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 3. In this session, we will cover desktop automation along with UI automation.
Topics covered:
UI automation Introduction,
UI automation Sample
Desktop automation flow
Pradeep Chinnala, Senior Consultant Automation Developer @WonderBotz and UiPath MVP
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
Keynote at DIGIT West Expo, Glasgow on 29 May 2024.
Cheryl Hung, ochery.com
Sr Director, Infrastructure Ecosystem, Arm.
The key trends across hardware, cloud and open-source; exploring how these areas are likely to mature and develop over the short and long-term, and then considering how organisations can position themselves to adapt and thrive.
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
Neuro-symbolic (NeSy) AI is on the rise. However, simply machine learning on just any symbolic structure is not sufficient to really harvest the gains of NeSy. These will only be gained when the symbolic structures have an actual semantics. I give an operational definition of semantics as “predictable inference”.
All of this illustrated with link prediction over knowledge graphs, but the argument is general.
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
PHP Frameworks: I want to break free (IPC Berlin 2024)Ralf Eggert
In this presentation, we examine the challenges and limitations of relying too heavily on PHP frameworks in web development. We discuss the history of PHP and its frameworks to understand how this dependence has evolved. The focus will be on providing concrete tips and strategies to reduce reliance on these frameworks, based on real-world examples and practical considerations. The goal is to equip developers with the skills and knowledge to create more flexible and future-proof web applications. We'll explore the importance of maintaining autonomy in a rapidly changing tech landscape and how to make informed decisions in PHP development.
This talk is aimed at encouraging a more independent approach to using PHP frameworks, moving towards a more flexible and future-proof approach to PHP development.
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Advanced php
1. More on PHP: Objects and Sessions
Autumn 2012
• Objects
• Defining objects
• Inheritance
• Sessions and session variables
2. Object oriented programming in PHP
• PHP, like most modern programming languages (C++, Java, Perl, JavaScript, etc.),
supports the creation of objects.
• Creating an object requires you to first define an object class (containing variables
and/or function definitions) and then using the “new” keyword to create an instance of
the object class. (Note that the object must be defined before you instantiate it.)
<?php
// Assume that the "Person" object has been previously defined. . .
$x = new Person; // creates an instance of the Person class (*no* quotes)
// The object type need not be "hardcoded" into the declaration.
$object_type = 'Person';
$y = new $object_type; // equivalent to $y = new Person;
$z = new Vehicle('Jaguar','green'); // creating an object and passing
// arguments to its constructor
?>
3. Defining (declaring) a class
• Use the “class” keyword which includes the class name (case-insensitive, but
otherwise following the rules for PHP identifiers). Note: The name “stdClass” is
reserved for use by the PHP interpreter.
<?php
class Person
{
var $name;
function set_name($new_name) {
$name = $this -> new_name;
}
function get_name() {
return $this -> name;
}
}
• Use the “$this” variable when accessing properties and functions of the current
object. Inside a method this variable contains a reference to the object on which
the method was called.
4. Declaring a class (cont.)
• Properties and functions can be declared as “public” (accessible outside the
object’s scope), “private” (accessible only by methods within the same class), or
“protected” (accessible only through the class methods and the class methods of
classes inheriting from the class.
• Note that unless a property is going to be explicitly declared as public, private, or
protected, it need not be declared before being used (like regular PHP variables).
<?php
class Person
{
protected $name;
protected $age;
function set_name($new_name) {
$name = $this -> new_name;
}
function get_name() {
return $this -> name;
}
}
5. Declaring a class (cont.)
• Classes can also have their own constants defined (using the “const” keyword),
can have their own static properties and functions (using the keyword “static”
before “var” or “function”), and can also can constructors and destructors (see
below).
• Static properties and functions are accessed (see below) using a different format
than usual for objects, and static functions cannot access the objects properties
(i.e. the variable $this is not defined inside of a static function).
<?php
class HTMLtable {
static function start() {
echo "<table> n";
}
static function end() {
echo "</table> n";
}
}
HTMLtable::start();
6. Accessing properties and methods
• Once you have an object, you access methods and properties (variables) of the
object using the -> notation.
<?php
$me = new Person;
$me -> set_name('Russ');
$me -> print_name();
$name = $me -> get_name();
echo $me -> get_name();
$age = 36;
$me -> set_age($age);
?>
7. Constructors and destructors
• Constructors are methods that are (generally) used to initialize the object’s
properties with values as the object is created. Declare a constructor function in an
object by writing a function with the name __construct().
<?php
class Person {
protected $name;
protected $age;
function __construct($new_name, $new_age) {
$this -> name = $new_name;
$this -> age = $new_age;
}
// . . . other functions here . . .
}
$p = new Person('Bob Jones', 45);
$q = new Person('Hamilton Lincoln', 67);
?>
• Destructors (defined with a function name of __destructor() ) are called when an
object is destroyed, such as when the last reference to an object is removed or the
end of the script is reached (the usefulness of destructors in PHP is limited, since,
for example dynamic memory allocation isn’t possible in the same way that it is in
C/C++).
8. Inheritance
• Use the “extends” keyword in the class definition to define a new object that inherits
from another.
<?php
class Employee extends Person {
var $salary;
function __construct($new_name, $new_age, $new_salary); {
$this -> salary = $new_salary;
parent::__construct($new_name, $new_age); // call the constructor
// of parent object
}
function update_salary($new_salary) {
$this -> salary = $new_salary;
}
$emp = new Employee('Dave Underwood', 25, 25000);
?>
9. Inheritance (cont.)
• The constructor of the parent isn’t called unless the child explicitly references it (as
in this previous case). There is no automatic chain of calls to constructors in a
sequence of objects defined through inheritance.
• You could “hard-code” the call to the parent constructor using the function call
“Person::__construct($new_name, $new_age);” but it’s typically better to define
it in the manner given using the parent::method() notation. The same manner is
used to call the method of a parent that has been overridden by its child.
• You can use the “self” keyword to ensure that a method is called on the current
class (if a method might be subclassed), in this style self::method();
• To check if an object is of a particular class, you can use the instanceof
operator.
if ($p instanceof Employee) {
// do something here
}
10. More on classes
• You can also define interfaces for objects (for which any object that uses that
interface must provide implementations of certain methods), and you can define
abstract classes or methods (that must be overridden by its children).
• The keyword “final” can be used to denote a method that cannot be overridden by
its children.
class Person {
var $name;
final function get_name() {
return $this -> name;
}
}
11. More on classes (cont.)
• There are methods for “introspection” about classes, i.e. the ability of a program to
examine an object’s characteristics.
For example, the function class_exists() can be used (surprise!) to determine
whether a class exists or not.
The function get_declared_classes() returns an array of declared classes.
$classes = get_declared_classes();
You can also get an array of method names in any of the following (equivalent)
manners:
$methods = get_class_methods(Person);
$methods = get_class_methods('Person');
$class = 'Person';
$methods = get_class_methods($class);
12. More introspection functions
• There are a wide variety of introspection functions, several more are listed below.
get_class_vars($object); /* gets an associative array that maps
property names to values (including
inherited properties), but it *only*
gets properties that have default
values (those initialized with
simple constants) */
is_object($object); // returns a boolean value
get_class($object); /* returns the class to which an object
belongs */
method_exists($object, $method); // returns a boolean value
get_object_vars($object); /* returns an associative array
mapping properties to values (for
those values that are set (i.e.
not null) */
13. A word about object methods…
• When defining the names of your own object methods, you should generally avoid
starting them with a double underscore. Why?
• There are some “built-in” or predefined PHP method names that start in this
manner, most notably constructors and destructors using the __construct() and
__destructor() names. In the future (in new versions of PHP), it’s possible that
further methods might be defined that begin with a double underscore.
• Other reserved method names include __sleep() and __wakeup() which are used
for object serialization and __get() and __set(), which can be defined so that if you
try to access an object property that doesn’t exist, these methods give an
opportunity to either retrieve a value or set the (default?) value for that property.
For example, if a class is used to represent data obtained from a database, you
could write __get() and __set() methods that read and write data whenever
requested.
14. PHP sessions
• By default, HTML and web servers don’t keep track of information entered on a
page when the client’s browser opens another page. Thus, doing anything
involving the same information across several pages can sometimes be difficult.
• Sessions help solve this problem by maintaining data during a user’s visit, and can
store data that can be accessed from page to page in your site.
• You can use session variables for storing information (this is one way that a
“shopping cart” function can work for an online shop, for example).
• Servers keep track of users’ sessions by using a session identifier, which is
generated by the server when a session starts and is then used by the browser
when it requests a page from the server. This session ID can be sent through a
cookie (the default behavior) or by passing the session ID in the URL string.
• Sessions only store information temporarily, so if you need to preserve information,
say, between visits to the same site, you should likely consider a method such as
using a cookie or a database to store such information.
15. PHP sessions (cont.)
• To start a session, use the function session_start() at the beginning of your PHP script
before you store or access any data. For the session to work properly, this function
needs to execute before any other header calls or other output is sent to the browser.
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Session example</title>
</head>
<body>
<?php
include_once ('object.php'); // Includes definition of the Person class
$_SESSION['hello'] = 'Hello world';
echo $_SESSION['hello'] . "<br/><br/>n";
$_SESSION['one'] = 'one';
$_SESSION['two'] = 'two';
$me = new Person("Russ", 36, 2892700);
$_SESSION['name'] = $me->get_name();
echo "Testing " . $_SESSION['one'] .", " . $_SESSION['two'] . ", " . $me-
>get_number() . " . . .<br/>n";
?>
</body></html>
view the output page
16. Using session variables
• Once a session variable has been defined, you can access it from other pages.
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Session example 2</title>
</head>
<body>
<?php
echo "Welcome to a new page ". $_SESSION['name'] "!<br/>n";
echo "Hope you enjoy your stay! <br/>";
?>
<p>Back to regular HTML text...
</p>
</body>
</html> view the output page
17. More on session variables
• You need to include a call to the session_start() function for each page on which
you want to access the session variables.
• A session will end once you quit the browser (unless you’ve set appropriate
cookies that will persist), or you can call the session_destroy() function. (Note,
however, even after calling the session_destroy() function, session variables are
still available to the rest of the currently executing PHP page.)
• The function session_unset() removes all session variables. If you want to remove
one variable, use the unset($var) function call.
• The default timeout for session files is 24 minutes. It’s possible to change this
timeout.
18. Deleting all session variables
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Session example 3</title>
</head>
<body>
<?php
echo "Deleting all session variables using session_unset(); <br/>n";
session_unset();
echo "Now the session variables are gone. <br/>n";
if (isset($_SESSION['name']))
{ echo $_SESSION['name'] . "<br/>n"; }
else
{ echo "Session variable is not here."; }
?>
</body> view the output page
</html>
19. Learning Outcomes
• A (very, very brief) introduction to objects in PHP. If you
wish to use objects, then many books on PHP include more
information, and, of course, much information is available
online.
• Sessions are useful for persistence of variables across
many webpages without the need to submit information via
forms.