PDA

View Full Version : ->


Phip
07-27-2002, 12:01 AM
what is " -> " ?

gorilla1
07-27-2002, 01:26 AM
As in object, property relationship?

G

Spookster
07-27-2002, 01:29 AM
That's easy. It's an arrow. :D


Ok ok. That particular arrow in PHP is a way to refer to a method or variable of an object. An object such as a class is a good example:


<?php

class HelloWorld {

var $hello;

function HelloWorld(){
$this->hello = "Hello PHP newbie";
}

function say_hello(){
return $this->hello;
}
}

$my_class = new HelloWorld;
echo $my_class->say_hello();


?>


That is just a simple example of creating a class and putting a function in there that returns a string. To refer to the function within that class we first create an instance of it

$my_class = new HelloWord;

then to access the function within it we use the arrow

$my_class->function_name();

Phip
07-27-2002, 03:14 AM
aahhh ok.. cool thanks

Phip
07-27-2002, 03:20 AM
what a second...

sense when did you need var for a variable?

what on earth is a class? i can't find it on php.net

new? what is new?

Spookster
07-27-2002, 03:38 AM
PHP has the capability of doing object oriented programming. A class is simply a way to package up functions to perfom certain tasks. This class is considered an object. When you want to use that object you have to create an instance of it. In object oriented programming this is called object instantiation. The new keyword is used to create an instance of an object like so:

$my_class = new HelloWorld;

This creates an instance of the object class HelloWorld and assigned to the variable $my_class. That variable acts as a reference and holds the object you just created.

Here is a decent tutorial that goes into in more depth.

http://www.zend.com/zend/tut/class-intro.php

It is a very useful feature of PHP.

Here is some more about object oriented programming on php.net:

http://www.php.net/manual/en/language.oop.php

Spookster
07-27-2002, 08:30 AM
Originally posted by Phip
what a second...

sense when did you need var for a variable?



since I put it inside the class. Variables and functions inside a class are referred to as member variables and member functions. This mean that they are a member of that object. The object being the class.