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
| SitePoint Sponsor |
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





http://www.php.net/manual/en/language.oop5.php
-> calls an object function (known as a method) or refers to a property
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.PHP Code:$object = new className($argument_to_constructor);
$object->do_something();

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.


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.
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:
class person
{
function add()
{
//
}
}
This would read this instance of person add. There is allot more to it I would start with this book.PHP Code:
$person = new person;
$person->add();
Bookmarks