SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: classes

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    classes

    could some one give a crash course on classes
    or explain what they are for/ how you use them

    more specifically i would like to know what the "->" is used for

  2. #2
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.php.net/manual/en/language.oop5.php

    -> calls an object function (known as a method) or refers to a property
    PHP Code:
    $object = new className($argument_to_constructor);
    $object->do_something(); 
    Here a new object called $object is created. It's got a class type of 'className' and I've called a method called do_something.

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    There are two distinct things to learn when it comes to oop.

    1 Getting the syntax right. Thats very much a read the manual thing to start with, then play around with some simple classes you make and search this forum when you get stuck, failing that ask a question.

    2 Use OOP correctly, again read the manual for starters, but then splash out on a good book, and there are lots and lots of good posts in the Php Application Design forum that you can search through for examples.

    There are lots of posts in this forum on oop books, search for that term.

    To learn the syntax should take a couple of days, to learn how to program in OOP should take a couple of years.

  4. #4
    SitePoint Addict
    Join Date
    Aug 2007
    Location
    St. Louis, MO.
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One of the things that finally made OOP click for me is when I started reading the '->' as 'this instance of.

    So lets say you have a class called user. The class would look something like this.

    PHP Code:

    class person
    {
       function 
    add()
       {
          
    // 
       
    }

    then on the page that you are using the class you instantiate it. Create an instance of the person. And then call your method (same thing as a function)

    PHP Code:

    $person 
    = new person;

    $person->add(); 
    This would read this instance of person add. There is allot more to it I would start with this book.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •