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.
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:
Advanced Theories
Inheriting Classes
Inheriting Constructors and Destructors
Overriding Methods
Access Control
Using the Scope Resolution Operator
Creating Static Members
Abstract Classes and Methods
For beginners who want to go to the next level of OOP in PHP, we talk about magic methods, iterators, filters, some parts of the SPL, the subject/observer pattern and how you can build classes that have a lot of power and responsibility by implementing interfaces and then type-hinting and using just methods that are defined in the interface. Prefer composition over inheritance.
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
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.
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
For beginners who want to go to the next level of OOP in PHP, we talk about magic methods, iterators, filters, some parts of the SPL, the subject/observer pattern and how you can build classes that have a lot of power and responsibility by implementing interfaces and then type-hinting and using just methods that are defined in the interface. Prefer composition over inheritance.
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
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, Interfaces and Scope: whether you’ve been programming in PHP for years or are just starting your journey, these terms can be overwhelming. 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.
Real life examples of Object-Oriented terminology in a way that makes sense and allows 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.
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.
Elasticsearch is a powerful, distributed, open source searching technology. By integrating Elasticsearch into your application, you instantly provide a way to search a lot of data very quickly. Elasticsearch has a RESTful API, it scales, its super fast, you can use plugins to customize it, and much more. In this talk I go over the basics of setting up Elasticsearch, creating a search index, importing your data, and doing some basic searching. I also touch on a few advanced topics that will show the flexibility of this awesome service.
Providing an Application Programming Interface (or API) has become a crucial piece of the modern web application. API’s provide opportunities to build the ecosystem around your application, opening doors for collaboration and innovative mashups. However, the API opens up another entry point into your application, requiring that you somehow secure the access to it.
This talk will outline some of the options you have when securing your API. I’ll give overviews and implementation tips on some of the more popular schemes such as OAuth, HTTP authentication, and generating API keys. We’ll also look at some general API best practices such as rate limiting, error handling, and secure data communication.
Mobile devices have become an integral part of the university environment – providing computing and connectivity in a way never before possible. Join ECU, NC State, and UNC-W for a panel discussion on organizing, implementing and deploying mobile-based services on campus.
Steve Forehand will talk about ECU's Onestop Mobile campus portal, which allows students to access course grades, course schedules, schedule appointments with their adviser, access Self Service Banner, and more.
Jason Austin will talk about organizing and growing NC State's mobile initiatives, ranging from their mobile Web site, iPhone applications, location-based applications and more.
Jeff Brown will talk about UNC-W's Value Add in the Hand initiative, which mixes text messaging with campus services and mobile gaming.
Emphasis will be on lessons learned and challenges encountered. Real-world examples will be highlighted.
Implementing software development “best practices” can be a challenging feat, especially if you are in a very small team of developers. Little to no budget, stress to just “get something out”, and lack of understanding from management of what you really do means you have to make sacrifices, right? This talk will give you some insight on accomplishing your goals of being a top-rated development shop, even if you are an army of one. From justifying those best practices to utilizing free services to hiring additional help, this talk will run the gamut of running a software development shop at a small scale.
Web Hosting Pilot - NC State UniversityJason Austin
NC State University has been working to put together a pilot project to extend the capabilities for web hosting on campus. This is a preliminary report of the progress of the project, given at a "Lunch and Learn" series on Dec. 1 2009.
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
As AI technology is pushing into IT I was wondering myself, as an “infrastructure container kubernetes guy”, how get this fancy AI technology get managed from an infrastructure operational view? Is it possible to apply our lovely cloud native principals as well? What benefit’s both technologies could bring to each other?
Let me take this questions and provide you a short journey through existing deployment models and use cases for AI software. On practical examples, we discuss what cloud/on-premise strategy we may need for applying it to our own infrastructure to get it to work from an enterprise perspective. I want to give an overview about infrastructure requirements and technologies, what could be beneficial or limiting your AI use cases in an enterprise environment. An interactive Demo will give you some insides, what approaches I got already working for real.
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.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
DevOps and Testing slides at DASA ConnectKari Kakkonen
My and Rik Marselis slides at 30.5.2024 DASA Connect conference. We discuss about what is testing, then what is agile testing and finally what is Testing in DevOps. Finally we had lovely workshop with the participants trying to find out different ways to think about quality and testing in different parts of the DevOps infinity loop.
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
In this insightful webinar, Inflectra explores how artificial intelligence (AI) is transforming software development and testing. Discover how AI-powered tools are revolutionizing every stage of the software development lifecycle (SDLC), from design and prototyping to testing, deployment, and monitoring.
Learn about:
• The Future of Testing: How AI is shifting testing towards verification, analysis, and higher-level skills, while reducing repetitive tasks.
• Test Automation: How AI-powered test case generation, optimization, and self-healing tests are making testing more efficient and effective.
• Visual Testing: Explore the emerging capabilities of AI in visual testing and how it's set to revolutionize UI verification.
• Inflectra's AI Solutions: See demonstrations of Inflectra's cutting-edge AI tools like the ChatGPT plugin and Azure Open AI platform, designed to streamline your testing process.
Whether you're a developer, tester, or QA professional, this webinar will give you valuable insights into how AI is shaping the future of software delivery.
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.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
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.
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.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
3. What makes good software?
"The function of good software is to make the complex
appear to be simple." - Grady Booch
"Always code as if the guy who ends up maintaining your
code will be a violent psychopath who knows where you
live." - Martin Golding
Good software needs good software engineering
5. What is software engineering then?
Software engineering is the application of a systematic,
quantifiable, disciplined approach to development.
Programming is simply one phase of development
6. PHP & Software Engineering
PHP is quick to learn, almost to a fault
Easy to write bad code
However, PHP provides tools to facilitate the creation of
solid and organized software
PHP started as a procedural language, but has evolved!
8. What’s Wrong With That!?
Nothing is really wrong with it. But...
It’s really hard to read and follow
As the code base grows, maintainability decreases
New additions often become hacks
Designers can’t easily design unless they know PHP
9. How else would I do it?!
Object Oriented Programming FTW!
10. What is OOP?
Programming paradigm using “objects” and their interactions
Not really popular until 1990’s
Basically the opposite of procedural programming
11. When would I use this OOP stuff?
When you...
find yourself repeating code
want to group certain functions together
want to easily share some of your code
want to have an organized code base
think you may reuse some of your code later
13. OOP Techniques
Before we get to the code, a little OOP primer
Encapsulation
Modularity
Inheritance
Polymorphism
14. Encapsulation (It’s like a Twinkie!)
Group together data and functionality (bananas and cream)
Hide implementation details (how they get the filling in there)
Provide an explicitly defined
way to interact with the data
(they’re always the same shape)
Hides the creamy center!
15. Modularity (It’s like this sofa!)
A property of an application that measures the extent to
which the application has been composed of separate parts
(modules)
Easier to have a more
loosely-coupled application
No one part is programatically
bound to another
16. Inheritance (It’s like Joan & Melissa Rivers)
A hierarchical way to organize data and functionality
Children receive functionality and properties of their
ancestors
is-a and has-a relationships
Inherently (hah!) encourages
code reuse
17. Polymorphism (It’s like that guy)
Combines all the other techniques
Kind of complicated so we’ll get to
it later
18. Need to know terms
class - A collection of interrelated functions and variables
that manipulates a single idea or concept.
instantiate - To allocate memory for a class.
object - An instance of a class
method - A function within a class
class member - A method or variable within a class
19. What does a class look like?
<?php
// this is a class. $name and getHeight() are class members
class Person
{
public $name = “Bob McSmithyPants”; // this is a class variable
public function getHeight() // this is a class method
{}
}
?>
20. How to instantiate a class
<?php
$p = new Person(); // at this point $p is a new Person object
?>
Now anyone can use the Person object (call its methods,
change its variables, etc.)
24. Public
Anyone (the class itself or any instantiation of that class) can have access to the
method or property
If not specified, a method or property is declared public by default
25. Public Example
<?php
class Person
{
public function getName()
{
return “Bob McSmithyPants”;
}
}
?>
<?php
$p = new Person();
echo $p->getName();
?>
27. Private Example
<?php
class Person
{
public function firstName()
{
return “Bob”;
}
private function lastName()
{
return “McSmithyPants”;
}
}
?>
<?php
$p = new Person();
echo $p->firstName(); // this will work
echo $p->lastName(); // this does not work
?>
28. Protected
Only the class itself or a class that extends this class can
have access to the method or property
29. Protected Example
<?php
class Person
{
protected function getName()
{
return “Bob McSmithyPants”;
}
}
class Bob extends Person
{
public function whatIsMyName()
{
return $this->getName();
}
}
?>
<?php
$p = new Person();
echo $p->getName(); // this won’t work
$b = new Bob();
echo $b->whatIsMyName(); // this will work
?>
30. What was with that $this stuff?
You can access the protected data and methods with “object
accessors”
These allow you to keep the bad guys out, but still let the good
guys in.
32. $this
variable
refers to the current instantiation
<?php
class Person
{
public $name = ‘bob’;
public function getName()
{
return $this->name;
}
}
$p = new Person();
echo $p->getName();
// will print bob
?>
33. self
keyword that refers to the class itself regardless of
instantiation status
not a variable
<?php
class Person
{
public static $name = ‘bob’;
public function getName()
{
return self::$name;
}
}
$p = new Person();
echo $p->getName();
// will print bob
?>
34. parent
<?php
class Person keyword that refers to the parent class
{
public $name = ‘bob’;
most often used when overriding
public function getName()
{ methods
return $this->name;
}
} also not a variable!
class Bob extends Person
{ What would happen if we used
public function getName()
{ $this->getName() instead of
}
return strtoupper(parent::getName()); parent::getName()?
}
$bob = new Bob();
echo $bob->getName();
// will print BOB
?>
35. Class constants
Defined with the “const” keyword
Always static
Not declared or used with $
Must be a constant expression, not a variable, class member,
result of a mathematical expression or a function call
Must start with a letter
36. Constant Example
<?php
class DanielFaraday
{
const MY_CONSTANT = 'Desmond';
public static function getMyConstant()
{
return self::MY_CONSTANT;
}
}
echo DanielFaraday::MY_CONSTANT;
echo DanielFaraday::getMyConstant();
$crazyTimeTravelDude = new DanielFaraday();
echo $crazyTimeTravelDude->getMyConstant();
?>
37. Class and Method Properties
Final and Static
Classes and methods can be declared either final, static, or
both!
38. Important Note!
Class member scopes (public, private, and protected) and
the class and method properties (final and static) are not
mutually exclusive!
40. Final Example
<?php
class Person
{
public final function getName()
{
return “Steve Dave”;
}
}
class Bob extends Person
{
public function getName()
{
return “Bob McSmithyPants”;
}
}
// this will fail when trying to include Bob
?>
41. Static
A method declared as static can be accessed without
instantiating the class
You cannot use $this within static functions because $this
refers to the current instantiation
Accessed via the scope resolution operator ( :: )
i.e. – About::getVersion();
42. Static Example
<?php
class About
{
public static function getVersion()
{
return “Version 2.0”;
}
}
?>
<?php echo About::getVersion(); ?>
44. Abstract Classes
Never directly instantiated
Any subclass will have the properties and methods of the
abstract class
Useful for grouping generic functionality of subclassed
objects
At least one method must be declared as abstract
45. Abstract Example
<?php
<?php
abstract class Car
{ $honda = new Honda();
private $_color; $honda->setColor(“black”);
$honda->drive();
abstract public function drive();
?>
public function setColor($color)
{
$this->_color = $color;
}
public function getColor()
{
return $this->_color;
}
}
class Honda extends Car
{
public function drive()
{
$color = $this->getColor();
echo “I’m driving a $color car!”;
}
}
?>
46. Interfaces
Defines which methods are required for implementing an
object
Specifies the abstract intention of a class without providing
any implementation
Like a blueprint or template
A class can simultaneously implement multiple interfaces
47. Interface Example
<?php
<?php
interface Car
{ $honda = new Honda();
public function start(); $honda->start();
public function drive(); $honda->drive();
public function stop(); $honda->stop();
} ?>
class Honda implements Car
{
public function start()
{
echo “Car is started!”;
}
public function drive()
{
echo “I’m driving!”;
}
public function stop()
{
echo “The car has stopped!”;
}
}
?>
48. instanceof
Operator to check if one class is an instance of another class
<?php
<?php
class Car
class Car
{}
{}
class Honda extends Car
class Honda extends Car
{}
{}
$car = new Car(); OR $car = new Honda();
$honda = new Honda();
if ($car instanceof Car) {
if ($car instanceof $honda) {
echo “true”;
echo “true”;
} else {
} else {
echo “false”;
echo “false”;
}
}
?>
?>
What will get printed?
49. Type Hinting
PHP is not strongly typed (i.e. - variables can be
pretty much anything anytime)
In PHP4 you have to do a lot of checking
to find out if a parameter is the correct type
Type Hinting helps make this more efficient
50. Type Hinting Example
<?php
// this can be made better with type hinting!
public function promoteToManager($bob)
{
if (!is_a($bob, “Person”)) {
throw new Exception(“$bob is not a Person!”);
}
// do stuff with $bob
}
?>
... becomes ...
<?php
// this is better!
public function promoteToManager(Person $bob)
{
// do stuff with $bob
}
?>
51. A Few More Terms
serialize - Converting an object to a binary form (i.e. -
writing an object to a file)
unserialize - The opposite of serialize. To convert the
stored binary representation of an object back into the
object.
reference - An pointer to an object’s location in memory
rather than the actual object
52. Magic Methods
Methods provided by PHP5 automagically (called by PHP on certain events)
Always begin with __ (two underscores)
Declared public by default but can be overridden
54. __construct() & __destruct()
__construct() runs when a new object is instantiated.
Suitable for any initialization that the object may need before
it’s used.
__destruct() runs when all references to an object are no
longer needed or when the object is explicitly destroyed.
55. __get()
__get() is called when trying to access an undeclared
property
<?php
class Car
{
protected $_data = array(
‘door’ => 4,
‘type’ => ‘Jeep’,
‘vin’ => ‘2948ABJDKZLE’
);
public function __get($varName)
{
return $this->_data[$varName];
}
}
$car = new Car();
echo $car->vin; // will print out 2948ABJDKZLE
?>
56. __set()
__set() is called when trying to assign an undeclared
property
<?php
class Car
{
protected $_data = array(
‘door’ => 4,
‘type’ => ‘Jeep’,
‘vin’ => ‘2948ABJDKZLE’
);
public function __set($varName, $value)
{
$this->_data[$varName] = $value;
}
}
$car = new Car();
$car->vin = ‘ABC’;
echo $car->vin; // will print out ABC
?>
57. __isset()
Used to check whether or not a data member has been declared
<?php
class Car
{
protected $_data = array(
‘door’ => 4,
‘type’ => ‘Jeep’,
‘vin’ => ‘2948ABJDKZLE’
);
public function __isset($varName)
{
return isset($this->_data[$varName]);
}
}
$car = new Car();
if (isset($car->color)) {
echo “color is set!”;
} else {
echo “color isn’t set!”;
}
// will print color isn’t set
?>
58. __unset()
Removes a data member from a class
<?php
class Car
{
protected $_data = array(
‘door’ => 4,
‘type’ => ‘Jeep’,
‘vin’ => ‘2948ABJDKZLE’
);
public function __unset($varName)
{
return unset($this->_data[$varName]);
}
}
$car = new Car();
unset($car->vin);
if (isset($car->vin)) {
echo “vin is set!”;
} else {
echo “vin isn’t set!”;
}
// will print vin isn’t set
?>
59. __call()
__call() is executed when trying to access a method that
doesn’t exist
This allows you to handle unknown functions however you’d
like.
60. _call() Example
<?php
class Sample
{
public function __call($func, $arguments)
{
echo "Error accessing undefined Method<br />";
echo "Method Called: " . $func . "<br />";
echo "Argument passed to the Method: ";
print_r($arguments);
}
}
$sample = new Sample();
echo $sample->doSomeStuff("Test");
?>
61. __toString()
Returns the string representation of a class
Is automatically called whenever trying to print or echo a
class.
Useful for defining exactly what you want an object to look
like as a string
Can also be used to prevent people from printing the class
without throwing an exception
62. __toString() Example
<?php
class SqlQuery
{
protected $_table;
protected $_where;
protected $_orderBy;
protected $_limit;
public function __construct($table, $where, $orderBy, $limit)
{
$this->_table = $table;
$this->_where = $where;
$this->_orderBy = $orderBy;
$this->_limit = $limit;
}
public function __toString()
{
$query = “SELECT * “
. “FROM $this->_table “
. “WHERE $this->_where “
. “ORDER BY $this->_orderBy “
. “LIMIT $this->_limit”;
return $query;
}
}
$test = new SqlQuery('tbl_users', “userType = ‘admin’”, ‘name’, 10);
echo $test;
?>
63. __sleep()
Called while serializing an object
__sleep() lets you define how you want the object to be
stored
Also allows you to do any clean up you want before
serialization
Used in conjunction with __wakeup()
64. __wakeup()
The opposite of __sleep() basically
Called when an object is being unserialized
Allows you to restore the class data to its normal form
65. __clone()
In php setting one object to another
does not copy the original object;
only a reference to the original is
made
To actually get a second copy of the
object, you must use the __clone
method
66. __clone() example
<?php
class Animal
{
public $color;
public function setColor($color)
{
$this->color = $color;
}
public function __clone()
{
echo "<br />Cloning animal...";
}
}
$tiger = new Animal();
$tiger->color = "Orange";
$unicorn = clone $tiger;
$unicorn->color = "white";
echo "<br /> A tiger is " . $tiger->color;
echo "<br /> A unicorn is " . $unicorn->color;
?>
67. __autoload()
Called when you try to load a class in a file that was not
already included
Allows you to do new myClass() without having to include
myClass.php first.
68. _autoload() example
<?php
class Account
{
public function __autoload($classname)
{
require_once $classname . ‘.php’; //$classname will be Profile
}
public function __construct()
{
$profile = new Profile();
}
}
?>
69. A little example
You can use all this stuff you just learned about inheritance,
scoping, interfaces, and abstract classes to do some more
complex things!
70. How Would You Solve This?
I have a bunch of shapes of which I want to find the area
I could get any combination of different shapes
I want to be able to find the area without having to know
the details of the calculation myself.
What OOP techniques could we use to solve this problem?
72. Polymorphism
The last object-oriented technique!
Combination of the other techniques
Allowing values of different types to be handled by a uniform
interface
75. Polymorphism
<?php
abstract class Shape
{
private $_color;
public function __construct($color)
{
$this->_color = $color;
}
public function getColor()
{
return $this->_color;
}
}
?>
76. Polymorphism
<?php
class Rectangle extends Shape implements HasArea
{
private $_w; // width
private $_h; // height
public function __construct($color, $w, $h)
{
parent::__construct($color);
$this->_w = $w;
$this->_h = $h;
}
public function area()
{
return ($this->_w * $this->_h);
}
}
?>
77. Polymorphism
<?php
class Circle extends Shape implements HasArea
{
private $_r; // radius
public function __construct($color, $r)
{
parent::__construct($color);
$this->_r = $r;
}
public function area()
{
return (3.14 * pow($this->_r, 2));
}
}
?>
78. Polymorphism
<?php
// this function will only take a shape that implements HasArea
function getArea(HasArea $shape)
{
return $shape->area();
}
$shapes = array(
'rectangle' => new Rectangle("red", 2, 3),
'circle' => new Circle("orange", 4)
);
foreach ($shapes as $shapeName => $shape) {
$area = getArea($shape);
echo $shapeName . " has an area of " . $area . "<br />";
}
// will print:
// rectangle has an area of 6
// circle has an area of 50.24
?>
79. QUESTIONS?
Jason Austin
@jason_austin
jfaustin@gmail.com
http://jasonawesome.com
Editor's Notes
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
Describe a little about how exactly a class becomes an object and how that works with respect to interacting with an object in memory and not the class specifically\n