Jump to content

Archived

This topic is now archived and is closed to further replies.

emehrkay

how do you say "->" ?

Recommended Posts

you know as you type along you do x equals y
$x = $y;

what do you say when you do this?
$this->

i usually say this into...

does the -> have an actual name?

Share this post


Link to post
Share on other sites
this may be a bit of an oversimplification, but after searching the PHP manual for a solution and coming up NULL, i figured i'd share my thoughts:

i generally simply refer to it as a "pointer."

i know i have to be careful, especially working with C++ programmers since it's a different animal than pointers in C, but that's my take on it. since it's not really an operator, i don't know that it has a name

Share this post


Link to post
Share on other sites
According to [url=http://uk.php.net/manual/en/tokens.php]this page[/url] (2/3 down the page) its called the Object operator.

When I type the following:
$this->method();
I basically say call internal function method();

Share this post


Link to post
Share on other sites
[quote author=wildteen88]
According to [url=http://uk.php.net/manual/en/tokens.php]this page[/url] (2/3 down the page) its called the Object operator.
[/quote]
very good eyes, wildteen

[quote author=wildteen88]
When I type the following:
$this->method();
I basically say call interal function method();
[/quote]
very similar here. i usually simply say something like "Object function method()." sometimes i'll go so far as to replace "Object" with the name of the Class it belongs to, if I'm working with multiple classes that have the same function names.

Share this post


Link to post
Share on other sites
[quote author=emehrkay]
you know as you type along you do x equals y
$x = $y;

what do you say when you do this?
$this->

i usually say this into...

does the -> have an actual name?
[/quote]
actually,

$x = $y;

means assign the value of $y to $x.  it is not the same as saying $x equals $y. $x equal $y is what you'd say in a condition, like, if ($x == $y) { .. }  that is, if $x equals $y. 

= is assignment operator.
== is equality

as far as $this->blah .. if i have this:

$foo->bar = 'blah';

i usually say "assign 'blah' to bar of foo," or "assign 'blah' to foo's bar"

That's just how i 'say' it :\

Share this post


Link to post
Share on other sites
to

i am watching a slideshow of a class given by zend on oo php and the guy says "to"

$b->a

"b to a"

Share this post


Link to post
Share on other sites
i normal say "owns" (in my head of course).

not cos i'm some sort of 10 year old gaming txt spkr, but because that's how i kinda got to understand it.

$this->that (this owns that, or that belongs to this)
$b->a (b owns a, or a belongs to b)

Share this post


Link to post
Share on other sites
When I'm typing it, I generally call it "dot" because I started OOP with Java, and I just think to myself
class.method()
so I transfered that to php
$class->method() is still class dot method to me...
I guess I'm just weird. I've never had to say it out loud.

Share this post


Link to post
Share on other sites
[quote author=jesirose link=topic=96282.msg534487#msg534487 date=1172014080]
When I'm typing it, I generally call it "dot" because I started OOP with Java, and I just think to myself
[/quote]

That's exactly what I do - I say "dot" in my mind, but my fingers make the translation from "." to "->" all on their own.

Share this post


Link to post
Share on other sites
I never really read my code aloud, but I have sometimes wondered how I would explain some code if I had to since I do not know the names.
--
[quote author=redbullmarky link=topic=96282.msg534430#msg534430 date=1172008707]
i normal say "owns" (in my head of course).

not cos i'm some sort of 10 year old gaming txt spkr, but because that's how i kinda got to understand it.

$this->that (this owns that, or that belongs to this)
$b->a (b owns a, or a belongs to b)
[/quote]
0wn3d!!!1!!one1

Share this post


Link to post
Share on other sites
I don't call it anything or translate it into any sort of phrase.

Although if I did, I suppose I'd go with the following:

$foo->bar = 1;  ==> foo's bar equals 1

$foo->bar(); ==> foo does bar

Share this post


Link to post
Share on other sites
I wonder why php used this syntax as they couldv'e easily used the "." operator as all other C type langs do. Java, C#, javascript and obviously c++.

Technically, "->" operator is used in c++ when accessing an object from a pointer. that is,
[code]
obj* obj1= &someobj;
*obj->method;
[/code]

I don't know the internals of php. But I think "->" is used just because "." is already "married??" with string concatation. Not because php uses pointers to access objs. 

Ok way offtopic. I call it dot. why bother using another word.

Share this post


Link to post
Share on other sites
You answered your own question there... they can't just as easily use it because it's already being used...

Share this post


Link to post
Share on other sites
I can't say why the PHP developers chose the -> operator over the dot operator, but I disagree with jesi's comment.

It's not terribly difficult to have one operator that performs different operations depending on the context in which it's used.  PHP already does it with LPAREN, which denotes function arguments or order of operations.  C++ uses context to allow function overloading.  Javascript uses the + operator for both string concatenation and arithmetic addition.

Share this post


Link to post
Share on other sites
Personally I dont use ->

but thats because I am RUBBISH and scared of classes of my own......

so using Roopurt's analogy
[quote]
$foo->bar(); ==> foo does bar
[/quote]

for me it should be

[quote]
$I!->classes(); ==> I do not do classes
[/quote]

Share this post


Link to post
Share on other sites
[quote author=roopurt18 link=topic=96282.msg537457#msg537457 date=1172314033]
I can't say why the PHP developers chose the -> operator over the dot operator, but I disagree with jesi's comment.

It's not terribly difficult to have one operator that performs different operations depending on the context in which it's used.  PHP already does it with LPAREN, which denotes function arguments or order of operations.  C++ uses context to allow function overloading.  Javascript uses the + operator for both string concatenation and arithmetic addition.
[/quote]

But then we wouldn't be able to:

[code=php:0]$obj->{$foo.$bar}();
${$foo.$bar}->foobar;
$obj->${$foo.'bar'};[/code]

String concatenation and arithmetic addition are things that can't be combined in such a way.

Share this post


Link to post
Share on other sites
Of course if the php string concatenation operator where to change to the plus sign:

[code=php:0]
$obj.{$foo+$bar}();
${$foo+$bar}.foobar;
$obj.${$foo+'bar'};[/code]

::)

Share this post


Link to post
Share on other sites
I personally say "calls"... $dog->bark();

So in my head, I say "dog calls bark".  When I'm referencing a class variable "$dog->poop = yellow" I just simply say dog poop equals yellow... I personally think it differs depending on whether you're referencing a variable or a method/function.

Share this post


Link to post
Share on other sites
[quote author=448191 link=topic=96282.msg537515#msg537515 date=1172326465]
But then we wouldn't be able to:

[code=php:0]$obj->{$foo.$bar}();
${$foo.$bar}->foobar;
$obj->${$foo.'bar'};[/code]
[/quote]

Not so.

[code]<?php
$obj->{$foo.$bar}();
// Would become...
$obj.{$foo.$bar}();
?>[/code]
If $foo is an object, we mean the property of $foo indicated by the variable $bar.  If $foo is not an object, we mean string concatenation, since there is no LPAREN after $bar.
If $obj is an object, we mean to call the method of $obj named after the concatenation of the variables $foo and $bar.  If $obj is not an object, we mean to concatenate the contents of $obj with the results of the function named after the concatenation of the variables $foo and $bar.

[code]<?php
${$foo.$bar}->foobar;
// Would become
${$foo.$bar}.foobar;
?>[/code]
If $foo is an object, we mean the property of $foo indicated by the contents of $bar.  If $foo is not an object, we mean string concatenation of $foo and $bar since $bar has no trailing LPAREN.
If the variable named for the result of the curly bracket expression is itself an object, we mean the foobar property of that object, otherwise you have a syntax error (expected T_DOLLAR_SIGN before 'foobar').

[code]<?php
$obj->${$foo.'bar'};
// Would become
$obj.${$foo.'bar'};
?>[/code]
If $foo is an object, it is converted to the string 'object' and concatenated with 'bar'.  This is done because 'bar' is not a legal identifier.  Otherwise the contents of $foo are concatenated with 'bar'.
If $obj is an object, we mean the property contained within the variable named by the curly bracket expression.  If $obj is not an object, we mean string concatenation.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.