I can't understand the basic idea and use of objects.I mean what is their use when coding.I'd be gratefull if someone could explain them.
Thanks in advance,
Constantine

    kostis12345;10915471 wrote:

    I can't understand the basic idea and use of objects.I mean what is their use when coding.I'd be gratefull if someone could explain them.
    Thanks in advance,
    Constantine

    That is a tall order to fill...

    Do you know PHP?

    Do you have any programming experience?

    Have you researched this topic any?

    Here is a link that will help, although there are millions of sources online.

    Amy

      here's my attempt at explaining it (in a short few paragraphs - I'm not the best at explaining things though):

      Objects, in a nutshell, is a type of data that allows you to gather data and functions all under a single variable. Think of it as a collection of correlating information, a grouped and contained system if you will.

      Classes can be viewed as the blueprints in which objects come from (called instantiating a class). Or you can think of this as a cookie cutter / template. It basically about reusability (with a few other benefits as well).

      You can create a bunch of loose variables to represent something (say a car.. you need a variable for the car's brand, colour, number of doors, transmittion, etc..). But these variable are procedural. It makes reusing quite poor, as well as letting anyone go into the code and set things in a poor manner... If you build a class of a car (which contains all the variables (properties) and functions (methods) within it, you can simply create a single new object by instantiating the class. As a result, this object contains everything about the car all collectively under one roof so to speak. As a result, you can keep creating new objects off this car class, each with their own values based off of a central collection of variables and functions.

      Additional advantages of classes is that you can have tight control over how object properties / methods are accessed. You can make properties / methods vary in visibility by making them either public, private or protected. If not public, this means that not just anyone can go into the code and set things procedurally.. this forces aspects of an object to be setup in a controlled manner..

      As well, classes can have children 😉 (by this, I mean, you can have classes extend off of other classes, thus potentially inheriting the parent class' attributes (which again plays into reusability).

      There's more (abstract classes, interfaces and whatnot), but that starts to get more deeply involved. OOP is a large enough subject in its own right. Learning it would serve you well. I'm sure other members here could explain things better, as this is not quite my forté, but hopefully, this gives a glimpse as to what is going on.

        I like to point people to this tutorial if they are very new to OOP. It starts out at a fairly high, conceptual level without even talking about code, then moves on to show how those concepts relate to actual classes and objects within the code. I guess you could say it provides a lot of the "why" for OOP.

        Then you can proceed to more PHP-specific syntax and implementation issues and learn the "how." Once you get beyond the very basics, I would recommend getting your hands on PHP 5 Objects, Patterns, and Practice by Matt Zandstra. At least in my case, that book helped get me past the n00b stage of using objects and into the "Now I get it!" stage of OOP in PHP. (I still have lots to "get", but I think I have most of the important concepts under control now.)

          Nice link Nog. Definitely explains thing better than I can 😉

            Yep, good link NogDog.

            I am a newbie to PHP and I personally like these books by Larry Ullman...

            Visual Quick Start: PHP For The World Wide Web

            Visual Quick Pro: PHP 6 and MySQL 5

            Visual Quick Pro: PHP 5 Advanced *gets into writing PHP in OOP style vs Procedurally

            If you make the effort, those three books will make you dangerous with PHP.

            (I'm on book #2 of my journey!)

            Amy

              WOW,lots of replies !Thanks everybody.Nrg I kinda get what you mean.Amy and Nog,thanks a lot for the links 😃

                Write a Reply...