Question About PHP Object Oriented Programming (OOP)

12 replies
Hello Warriors,

I am an intermediate php developer. I know most of the php logics, functions etc.. Recently, I have decided to step-in the PHP Object Oriented Programming (OOP). I have learn't all the basics and rules for PHP OOP. Now, I need to exactly where I can see its real application ?? In most of my recent searches, I have found some common examples like

Building a Pet Shop
Building the Persons classes
Building Animal classes

But, All in All, I didn't find its much usage. I exactly need to know that how can I create classes for a shopping cart, for a job site, for classified site etc..

If any body can refer me to any web application tutorial, I will be highly thankful to you. Because, I want to get my hands stronger on PHP OOP


Thanks
#object #oop #oriented #php #programming #question
  • Profile picture of the author phpbbxpert
    OOP is not about building applications.
    You missed the point from the examples that you pointed out.

    The point behind OOP is having highly extendable code.
    Along with organization of code, usually more optimized, and a lot easier to make an application modular.

    I'm sure you if look at those examples you will see that they are extending the classes.
    If done properly it also gets rid of things like globals, and repetitive coding.

    It's not just about classes either, there is quite a bit more to it.
    Interfaces, Namespaces, objects themselves, all of the extra keywords that come with OOP and PHP 5.
    There is a whole section on it in the PHP manual
    PHP: Classes and Objects - Manual

    This site has tutorials and a video series.
    http://www.killerphp.com/tutorials/object-oriented-php/
    {{ DiscussionBoard.errors[3751690].message }}
  • Profile picture of the author Adam Struve
    Sounds like you're over thinking things and creating more work for yourself. Now go MVC and start using CodeIgniter. That little framework has made me so much money and saved me so much time.
    {{ DiscussionBoard.errors[3752563].message }}
  • Profile picture of the author Jilawatan
    Phpbbexpert - Thanks for the reference and clearing another concept of mine. I have already read that tutorial . I have all the basic and fundamental concepts.


    ADAM - If you can further tell me more about PHP frameworks that what exactly they are ?? I have also read much about Zend framework and the last one you have define. Would u like to explain it further ??
    {{ DiscussionBoard.errors[3753912].message }}
  • Profile picture of the author ussher
    The one big thing i find very useful about OOP as opposed to procedural is that you can clean up your function names.

    if you were writing something without OOP you would need to make sure your function names don't clash.

    in something like drupal where it is not OOP you have to make an effort to make sure your functions aren't named the same as someone elses functions.

    They handle it by prefixing all the functions your module creates with the name of the module.

    so if you created a module "Blue_balloons" then all of your functions would look like this:
    Code:
    blue_balloons_show()
    blue_balloons_hide()
    blue_balloons_pop()
    blue_balloons_float()
    blue_balloons_do_something()
    so you know that your function names are unique. If this was OOP, you could shorten those names and not worry about clashes.
    $balloon = new blue_balloons

    then your function names look like this:
    Code:
    balloon->show()
    balloon->hide()
    balloon->pop()
    balloon->float()
    balloon->do_something()
    It makes things easier to read.
    Signature

    "Jamroom is a Profile Centric CMS system suitable as a development framework for building entire communities. Highly modular in concept. Suitable for enterprise level development teams or solo freelancers."

    - jamroom.net
    Download Jamroom free: Download
    {{ DiscussionBoard.errors[3766824].message }}
  • Profile picture of the author FreeBird85
    This book right here is IMO the best book available on learning OOP using PHP, I recommend it.

    PHP Object Oriented SolutionsPHP Object Oriented Solutions
    Signature

    {{ DiscussionBoard.errors[3767100].message }}
  • Profile picture of the author wayfarer
    It's good that you want to learn more about OOP. This will definitely open many doors for you. For one it will make you more useful professionally. For another, it will make learning other programming languages easier. PHP was the first language that I learned OOP on an advanced level. After this experience, I found that it was quite easy to understand the concept of Java and Python, which both implement classes in a similar manner.

    I think, once you study it, you'll find that the core concepts are not really very difficult. It's more just a set concepts that are very useful for managing larger systems, so don't be confused by the verbose terminology such as encapsulation, polymorphism, inheritance.

    Encapsulation simply means that objects (instances of classes) can have their own private variables (fields) and functions (methods) in which to operate, without interfering with the properties of other objects or classes.

    Polymorphism simply means that objects can take on many forms even though they are derived from the same class. This isn't really a feature, more just something that happens, depending on how classes are built and what their resulting objects are used for.

    Inheritance is very important, because it allows the programmer to implement new classes from existing classes, by extending them. When a class is extended, in inherits some or all of the former classes properties, and might overwrite some of the properties. This is a very useful way of creating new classes without needing to rewrite the old ones. Also, you can extend pre-existing classes this way (such as the mysqli class, which comes packaged with PHP 5). In addition, some classes are not made to be instantiated (made into an object), but are only intended to be extended into other classes. This is known as an abstract class, which basically serves as a template for other classes.
    Signature
    I build web things, server things. I help build the startup Veenome. | Remote Programming Jobs
    {{ DiscussionBoard.errors[3767997].message }}
  • Profile picture of the author Jilawatan
    Thanks all of you for helping me out. I know that there is no limit to learn. I don't think so that no body can be a complete programmer. Each time, we need someother one to get our hands completely on a new object. Thats why I am doing. In the last few days, I have create some small applications with the help of OOP. But, now I am little bit confuse.

    Since, I have got that we can use classes to execute our MySQL queries. Doing some image resizing, creating categories tree. I have got that. I am creating a shopping cart and every thing is going in a right manner. The confusion here for me is that I am using now only OOP for each page. I have created a separate file to hold all the classes.
    Infact, I am showing the HTML forms by using classes. No issue here. Only one thing is getting me into trouble that the classes.php file is becoming more heavy and heavy. Thats what, I am thinking about that Should I use classes only for executing MySQL queries or doing some other works like categories tree, image resizing etc..

    Please clear this thing to me !!
    {{ DiscussionBoard.errors[3774725].message }}
  • Profile picture of the author wayfarer
    Try autoloading your classes instead of putting them all into one file. The idea is to put each class in its own file, a file which has the same name as the class.

    PHP: Autoloading Classes - Manual
    Signature
    I build web things, server things. I help build the startup Veenome. | Remote Programming Jobs
    {{ DiscussionBoard.errors[3775665].message }}
    • Profile picture of the author ussher
      since classes are just boxes that do things.

      you can forget about how they work and just appreciate the results.

      say you wanted a file upload script, you can go somewhere like phpclasses.org and do a search for 'Upload' and you will get a ton of results.

      upload - PHP Classes


      instead of having to write the whole thing yourself, you can now just use re-use the code that has already been built.

      This can help move your production time forward.

      with things like:
      $file->Upload()
      $file->save()
      $file->saveAs()
      $file->getFilename()
      etc....
      Signature

      "Jamroom is a Profile Centric CMS system suitable as a development framework for building entire communities. Highly modular in concept. Suitable for enterprise level development teams or solo freelancers."

      - jamroom.net
      Download Jamroom free: Download
      {{ DiscussionBoard.errors[3780021].message }}
      • Profile picture of the author phpbbxpert
        Originally Posted by ussher View Post

        since classes are just boxes that do things.

        you can forget about how they work and just appreciate the results.
        And that is how sites get hacked.
        Knowing the code and what it does is 90% of the battle.
        Without knowing your setting yourself up.
        Security should always be the number one concern, that requires knowing the code
        and how it works.
        {{ DiscussionBoard.errors[3780972].message }}
  • Profile picture of the author Jilawatan
    Wayfarer - Thanks again for helping me out and telling me such an important thing about OOP. What I learnt is that not it can save only the time, but it can reduce your CPU usage as well. Autoload class function is such an awesome function by which we can get rid of rewriting the include and require statements again and again. Further, it only load that class which is really needed.



    Usser - You may be telling exactly a rite thing, But then what it means to be an expert. We can simply use the already written code for various purposes. But, I never feel comfortable with this. Because I want to write each and every code with my hands

    PHPbbexpert - You are absolutely write. Not only a single person, but a lot of person use that kind of codes which increase the security risk as well
    {{ DiscussionBoard.errors[3781492].message }}
  • Profile picture of the author sidharthbanyal
    I was not knowing that PHP is object oriented language.
    Signature

    Luck is dividend of Sweat. More you Sweat More you get luckier.

    {{ DiscussionBoard.errors[3793222].message }}

Trending Topics