Jump to content




Recent Status Updates

  • Photo
      18 Aug
    KodeKool

    When faced with a wall of errors and no hope to fix them, remember the following "Programs always do what you tell them to, and seldom what you want them to, but eventually you'll run out of things that can go wrong and it'll just work. and that's the secret to good programming."

    Show comments (2)
  • Photo
      11 Aug
    Error

    Should I be practicing programming every day? I feel if I don't, I'll get instantly rusty or something.

    Show comments (4)
View All Updates

Developed by Kemal Taskin
Photo
- - - - -

PHP OOP Tutorial from beginner to advance - (Introduction to OOP - Part 1)

php object oriented php object oriented tutorial basic advance basic to advance php

  • Please log in to reply
3 replies to this topic

#1 papabear

papabear

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 471 posts
  • Location:DarkSide

Posted 26 September 2012 - 07:50 AM

What is OOP?

Have you ever heard of the term OOP? or Object-Oriented Programming? If you are a programmer then you might have heard it many times to your teacher, co-worker, friend or into a stranger. If this is the first time that you have ever heard of that OOP thing then I'll explain it to you.

OOP or Object-Oriented Programming is a programming paradigm that uses objects.. it consists of several functions or methods that has a specific job to do. Programming techniques may include features such as data abstraction, inheritance, polymorphism and encapsulation. Almost every popular programming language now supports this.

Uh oh, there's a lot of new terms again.. what are objects? what is abstraction, inheritance, polymorphism and encapsulation?

Relax.. and continue reading :)


What are objects?

Objects are the computerized representation of real world objects it contains a collection of method or functions. They have a specific use, an attribute or property. A good example is a car.

A car is a real world object, its specific use is for transportation,, or if you are cool you can use it to get a girl :D just kidding...
A car has several properties or attributes like color, speed, weight, height, etc... just like an Object in the programming term.


What are those abstraction, inheritance, encapsulation and polymorphism thing?

Abstraction - it is the process by which data and programs are defined with representation similar in form to its semantics, while hiding away the implementation details.

Inheritance - it is a way to build an object with other object by sharing it's functions.

Encapsulation - it refers to one of two related but distinct notions.. It is used as a mechanism to restrict the access to some of the objects components.

Polymorphism - ​ is the ability to create a variable, a function, or an object that has more than one form.



Reasons why adopt OOP as a programming style

- Reusable code
- Easy to maintain
- Faster Software Development
- Produce high-quality programs
- Easy to adopt and Easy to scale


Some Facts

- The hardest part is STARTING OUT
- Procedural style is messy and a headache


here's an example object in PHP

class Dog {
public $color = "brown";
public $eyecolor = "brown";

public function talk() {
echo "Woof! Woof!";
}

public function run() {
echo "Your dog is running";
}

public function pee() {
echo "XD";
}
}

$dog = new Dog();
$dog->talk();
$dog->run();

output:
Woof! Woof! Your dog is running



if you don't know.. An Object is an instance of a class :)
That's it for this tutorial.. I hope you enjoyed reading this tutorial and thanks for giving me your time :D


More Powers
Papabear


Next Tutorial

Properties and $this - Part 2
  • 1
Life has no CTRL+Z
Never Forget To HIT "LIKE" If I Helped

#2 lespauled

lespauled

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,173 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash

Posted 26 September 2012 - 09:28 AM

I think you should go into a little more detail about the characteristics of OOP. Those 4 short descriptions might confuse new programmers.

Also procedural style being "messy" is not a fact. OOP programs can be messy too. It depends on the users abilities. In a lot of classes, you will find procedural code. The differences are that they act upon and are contained within the object.
  • 0
My Blog: http://forum.codecal...699-blog-77241/
"Women and Music: I'm always amazed by other people's choices." - David Lee Roth

#3 papabear

papabear

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 471 posts
  • Location:DarkSide

Posted 26 September 2012 - 02:59 PM

I think you should go into a little more detail about the characteristics of OOP. Those 4 short descriptions might confuse new programmers.

Also procedural style being "messy" is not a fact. OOP programs can be messy too. It depends on the users abilities. In a lot of classes, you will find procedural code. The differences are that they act upon and are contained within the object.


I only gave a short description in those four techniques because I want to explain them more in another part :)
and for me procedural is messy, you have to repeat the same code again while you can make a library of functions and just call it :)
Thanks for the comment :thumbup1:
  • 0
Life has no CTRL+Z
Never Forget To HIT "LIKE" If I Helped

#4 VNFox

VNFox

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 648 posts
  • Programming Language:C#, PHP
  • Learning:Assembly

Posted 26 September 2012 - 03:23 PM

Good start +1 ... keep on the good work.
  • 0

www.pickmike.com
I don't just develop software. I find solutions to your business needs.






Also tagged with one or more of these keywords: php, object oriented, php object oriented, tutorial, basic, advance, basic to advance php