PDA

View Full Version : difinition of ->



pghcollectibles
04-13-2008, 03:48 PM
i am having a hard time searching for this as im sure the search engine forms are stripping it away but i need to know what it means, to edit my template in oscommerce to be able to redeem my gift cirtificates through the website.

i have not found them in w3schools or php.net but i also saw => talking about adding to arrays and thought they may be similar. here is an example of a more complexed one.

<?php echo $currencies->format($cart->show_total()); ?>

with the parenthesis i would think these are functions not arrays, but function variables are usually inside the parenthesis so im not sure.

Seb
04-14-2008, 03:25 AM
The -> points to a property or function of an object. Objects are defined by classes. In the below example, $new_car is an object.

class Car
{
public $model = 'Volvo';

public function print_model()
{
echo $this->model;
}
}

$new_car = new Car();

echo $new_car->model; // Volvo
$new_car->print_model(); // Volvo
Read more about Object Oriented Programming (OOP) (http://en.wikipedia.org/wiki/Object_oriented). And OOP in PHP 5 (http://www.php.net/manual/en/language.oop5.php).

The => is used when defining and iterating over arrays to point to the actual value rather than the key.

$cars = array(
'Volvo',
'Toyota'
);

echo $cars[0]; // Volvo
echo $cars[1]; // Toyota

$cars = array(
'best' => 'Volvo',
'bad' => 'Toyota'
);

echo $cars['best']; // Volvo
echo $cars['bad']; // Toyota

pghcollectibles
04-14-2008, 08:06 PM
i might remember seeing that example but in your example you dont explain what happens to $this maybe i would understand if you pretended i knew nothing and walked through each line of code w/ comment on whats happening with your class example. i understand how the array works

pghcollectibles
04-14-2008, 08:28 PM
i guess i will eventually figure it out from the php.net info but that is pretty heavy reading. i understand $this. but i do not speak hebrew. (until now) Paamayim Nekudotayim holy cow. does this stuff get more complicated than this?