What is the difference between "=>" and "->" operators?

What is the difference between "=>" and "->" operators?

am 13.08.2007 12:27:19 von mejpark

Morning,

I'm currently working my way through a series of tutorials from IBM's
developer network called "Cook up Web sites fast with CakePHP". The
XAMPP 1.4.9 development platform consists of PHP Version 5.0.2, MySQL
3.23.57.

Here is an excerpt of code provided in the tutorial, which is used to
create a model:

class Dealer extends AppModel
{
var $name = 'Dealer';
var $hasMany = array ('Product' => array(
'className' => 'Product',
'conditions'=>,
'order'=>,
'foreignKey'=>'dealer_id')
);
}
?>


Eclipse produces an error underneath the comma directly after the
'conditions' field, which says:
"Parse error: "Static/scalar constant expected.""

I changed the code above, got it working and continued through the
tutorial:

class Dealer extends AppModel
{
var $name = 'Dealer';
var $hasMany = array (
"Product" =>
array("className","Product","conditions","order","foreignKey ","dealer_id"));
}
?>

The system works fine until I used Bake to implement an ACL. Each time
a new user registers, a rule is supposed to be enterred into the db
which defines what access level they have, but it doesn't work. When a
new user registers a new record should appear in the ACL tables. This
is the only thing that I can think might have caused a problem.

What is the difference between " => " and " -> " in PHP?

Cheers,

Michael

Re: What is the difference between "=>" and "->" operators?

am 13.08.2007 13:53:14 von Ulf Kadner

mejpark wrote:
> Morning,

Good? :-x


> > class Dealer extends AppModel
> {
> var $name = 'Dealer';
> var $hasMany = array ('Product' => array(
> 'className' => 'Product',
> 'conditions'=>,
> 'order'=>,

you forget do define the value, assigned to array keys 'conditions' and
'order'

> Eclipse produces an error underneath the comma directly after the
> 'conditions' field, which says:
> "Parse error: "Static/scalar constant expected.""

thats it, yes

> > class Dealer extends AppModel
> {
> var $name = 'Dealer';
> var $hasMany = array (
> "Product" =>
> array("className","Product","conditions","order","foreignKey ","dealer_id"));

Its usually not the same.
You are using now a numeric indicated array and not the required
associative array format.

You must read the documentation about arrays for understanding:
http://www.php.net/manual/en/language.types.array.php

> What is the difference between " => " and " -> " in PHP?

=> is only usable in array context. (see Array-Doc)

-> is to call some class sensitive Elements (e.g. Methods, Fields)
access only non static Elements

for accessing static class elements use the double colon ::

So Long. Ulf

Re: What is the difference between "=>" and "->" operators?

am 13.08.2007 14:15:03 von Toby A Inkster

mejpark wrote:

> What is the difference between " => " and " -> " in PHP?

'=>' is used when filling an array to provide an explicit key for a value.
e.g.:

$team = array(
'Bob',
'Steve',
'Dave',
'manager'=>'Harry'
);

is roughly equivalent to:

$team = array();
$team[0] = 'Bob';
$team[1] = 'Steve';
$team[2] = 'Dave';
$team['manager'] = 'Harry';

'->' is an entirely different operator. It has nothing to do with arrays.
It it used to reference an object property or method in object-oriented
programming. It is equivalent to Java's "." operator. e.g.

$myCup = new Cup($cupsize);
echo $myCup->fill(LIQUIDS_ORANGE_JUICE, '300 mL');
if ($myCup->percentageFilled==100)
{
echo "Cup is full.\n";
if ($myCup->hasOverflowed)
echo "Cup has overflowed!\n";
}
else
{
echo "There's still room for vodka!\n";
}


--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 53 days, 15:46.]

PHP Debugging with Style -OR- How I Learned to Stop Worrying and Love the Bug
http://tobyinkster.co.uk/blog/2007/08/12/php-debugging-with- style/

Re: What is the difference between "=>" and "->" operators?

am 13.08.2007 14:28:09 von mejpark

On Aug 13, 12:53 pm, Ulf Kadner wrote:
> mejpark wrote:
> > Morning,
>
> Good? :-x
>
> > > > class Dealer extends AppModel
> > {
> > var $name = 'Dealer';
> > var $hasMany = array ('Product' => array(
> > 'className' => 'Product',
> > 'conditions'=>,
> > 'order'=>,
>
> you forget do define the value, assigned to array keys 'conditions' and
> 'order'
>
> > Eclipse produces an error underneath the comma directly after the
> > 'conditions' field, which says:
> > "Parse error: "Static/scalar constant expected.""
>
> thats it, yes
>
> > > > class Dealer extends AppModel
> > {
> > var $name = 'Dealer';
> > var $hasMany = array (
> > "Product" =>
> > array("className","Product","conditions","order","foreignKey ","dealer_id"));
>
> Its usually not the same.
> You are using now a numeric indicated array and not the required
> associative array format.
>
> You must read the documentation about arrays for understanding:http://www.php.net/manual/en/language.types.ar ray.php
>
> > What is the difference between " => " and " -> " in PHP?
>
> => is only usable in array context. (see Array-Doc)
>
> -> is to call some class sensitive Elements (e.g. Methods, Fields)
> access only non static Elements
>
> for accessing static class elements use the double colon ::
>
> So Long. Ulf

Thanks for that Ulf, very helpful response!

Until next time >>

Re: What is the difference between "=>" and "->" operators?

am 23.08.2007 01:21:14 von mejpark

On Aug 13, 1:15 pm, Toby A Inkster
wrote:
> mejpark wrote:
> > What is thedifferencebetween " => " and " -> " in PHP?
>
> '=>' is used when filling an array to provide an explicit key for a value.
> e.g.:
>
> $team = array(
> 'Bob',
> 'Steve',
> 'Dave',
> 'manager'=>'Harry'
> );
>
> is roughly equivalent to:
>
> $team = array();
> $team[0] = 'Bob';
> $team[1] = 'Steve';
> $team[2] = 'Dave';
> $team['manager'] = 'Harry';
>
> '->' is an entirely different operator. It has nothing to do with arrays.
> It it used to reference an object property or method in object-oriented
> programming. It is equivalent to Java's "." operator. e.g.
>
> $myCup = new Cup($cupsize);
> echo $myCup->fill(LIQUIDS_ORANGE_JUICE, '300 mL');
> if ($myCup->percentageFilled==100)
> {
> echo "Cup is full.\n";
> if ($myCup->hasOverflowed)
> echo "Cup has overflowed!\n";
> }
> else
> {
> echo "There's still room for vodka!\n";
> }
>
> --
> Toby A Inkster BSc (Hons) ARCS
> [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
> [OS: Linux 2.6.12-12mdksmp, up 53 days, 15:46.]
>
> PHP Debugging with Style -OR- How I Learned to Stop Worrying and Love the Bug
> http://tobyinkster.co.uk/blog/2007/08/12/php-debugging-with- style/
Haha, very amusing example! Thankyou both for your explanations, that
has clarified thin gs in my mind! Right, back to ACLs and the Star
Wars example then!