473,385 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

what is the -> operator?

I'm looking at some code and found the -operator. In looking at the
PHP manual at php.net, I can't find a description of what it does. I
can find an example of where it is used, like on this page:
http://us2.php.net/manual/en/language.types.object.php

In the sample code like this:

<?php
class foo
{
function do_foo()
{
echo "Doing foo.";
}
}

$bar = new foo;
$bar->do_foo();
?>

But what does it do?

The code that triggered this search was this code:

function __construct()
{
$this->soap_client = new SoapClient($this->wsdl);
}
In the above, is the $this equivalent to "this" in other languages,
ie. an instance of the object itself? Again, a search of the manual at
php.net did not yield anything for the $this variable.

Thanks.
Jun 2 '08 #1
4 1685
On Jun 1, 5:45*pm, MikeB <MPBr...@gmail.comwrote:
I'm looking at some code and found the -operator. In looking at the
PHP manual at php.net, I can't find a description of what it does. I
can find an example of where it is used, like on this page:http://us2.php.net/manual/en/language.types.object.php

In the sample code like this:

<?php
class foo
{
* * function do_foo()
* * {
* * * * echo "Doing foo.";
* * }

}

$bar = new foo;
$bar->do_foo();
?>

But what does it do?

The code that triggered this search was this code:

* * function __construct()
* * {
* * * * $this->soap_client = new SoapClient($this->wsdl);
* * }

In the above, is the $this equivalent to "this" in other languages,
ie. an instance of the object itself? Again, a search of the manual at
php.net did not yield anything for the $this variable.

Thanks.
The part of the manual you must've missed is at:
http://us2.php.net/manual/en/language.oop5.php

$this is explained there in detail, and -by means of many clear
examples. Indeed, $this is like "this" in many other languages. -is
also like -in e.g. c++, and does the same as the dot in e.g. java,
python and ruby. The reason it isn't simply the dot in PHP is probably
because the dot also means string concatenation.

-egbert
Jun 2 '08 #2
On Jun 1, 11:15 am, Egbert Teeselink <skreb...@gmail.comwrote:
On Jun 1, 5:45 pm, MikeB <MPBr...@gmail.comwrote:
I'm looking at some code and found the -operator. In looking at the
PHP manual at php.net, I can't find a description of what it does. I
can find an example of where it is used, like on this page:http://us2.php.net/manual/en/language.types.object.php
In the sample code like this:
<?php
class foo
{
function do_foo()
{
echo "Doing foo.";
}
}
$bar = new foo;
$bar->do_foo();
?>
But what does it do?
The code that triggered this search was this code:
function __construct()
{
$this->soap_client = new SoapClient($this->wsdl);
}
In the above, is the $this equivalent to "this" in other languages,
ie. an instance of the object itself? Again, a search of the manual at
php.net did not yield anything for the $this variable.
Thanks.

The part of the manual you must've missed is at:http://us2.php.net/manual/en/language.oop5.php

$this is explained there in detail, and -by means of many clear
examples. Indeed, $this is like "this" in many other languages. -is
also like -in e.g. c++, and does the same as the dot in e.g. java,
python and ruby. The reason it isn't simply the dot in PHP is probably
because the dot also means string concatenation.

-egbert
You're right, I did miss that part. I've now read it, and the
preceding PHP 4 Object section.

I was still confused, so then I found this site:
http://www.sitepoint.com/article/object-oriented-php

After reading that I started getting some clarification, but I'm still
a little lost. Now my confusion extends to the double-colon and the
arrow operator.

If I have a class myClass with methods foo and bar

class MyClass{
function foo() {}
function bar() {}
}

then can I write

$thisVariable = myClass::foo /*static call */

and

$classInstance = new MyClass;
$classInstance->foo /* call the foo method in my instance? */

Am I at least on the right track? If there is a good book, about now
I'd be really glad to get a recommendation.

Thanks
Jun 2 '08 #3
MikeB schreef:
On Jun 1, 11:15 am, Egbert Teeselink <skreb...@gmail.comwrote:
>On Jun 1, 5:45 pm, MikeB <MPBr...@gmail.comwrote:
>>I'm looking at some code and found the -operator. In looking at the
PHP manual at php.net, I can't find a description of what it does. I
can find an example of where it is used, like on this page:http://us2.php.net/manual/en/language.types.object.php
In the sample code like this:
<?php
class foo
{
function do_foo()
{
echo "Doing foo.";
}
}
$bar = new foo;
$bar->do_foo();
?>
But what does it do?
The code that triggered this search was this code:
function __construct()
{
$this->soap_client = new SoapClient($this->wsdl);
}
In the above, is the $this equivalent to "this" in other languages,
ie. an instance of the object itself? Again, a search of the manual at
php.net did not yield anything for the $this variable.
Thanks.
The part of the manual you must've missed is at:http://us2.php.net/manual/en/language.oop5.php

$this is explained there in detail, and -by means of many clear
examples. Indeed, $this is like "this" in many other languages. -is
also like -in e.g. c++, and does the same as the dot in e.g. java,
python and ruby. The reason it isn't simply the dot in PHP is probably
because the dot also means string concatenation.

-egbert

You're right, I did miss that part. I've now read it, and the
preceding PHP 4 Object section.

I was still confused, so then I found this site:
http://www.sitepoint.com/article/object-oriented-php

After reading that I started getting some clarification, but I'm still
a little lost. Now my confusion extends to the double-colon and the
arrow operator.

If I have a class myClass with methods foo and bar

class MyClass{
function foo() {}
function bar() {}
}

then can I write

$thisVariable = myClass::foo /*static call */

and

$classInstance = new MyClass;
$classInstance->foo /* call the foo method in my instance? */

Am I at least on the right track? If there is a good book, about now
I'd be really glad to get a recommendation.

Thanks
Hi,

You can call a classmethod without instantiating the class first.
In that case we say it is a static call to that method (function).

That can be useful to the programmer to pack some functionality in a class.
For example, if you have a bunch of functions that manipulate strings in
some useful way, you can pack them together in a class; to organize your
code.

If you use $this-you must have an instantiated class, since the $this
points to that instantiation.

Regards,
Erwin Moller
Jun 27 '08 #4
MikeB wrote:
[...]
After reading that I started getting some clarification, but I'm still
a little lost. Now my confusion extends to the double-colon and the
arrow operator.
[...]
Am I at least on the right track?
Yes, you're on the right track.

-is the object resolution operator. It applies to instances of objects.

:: is the namespace resolution operator. It applies to classes: static stuff
when you're outside a class, and the very class and its parents when you're
inside of a class. In PHP6, it'll be used to refer to namespaces too.
If there is a good book, about now
Do read the PHP manual.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

OS/2: ¿Qué mitad deseas?
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: thecrow | last post by:
Alright, what the hell is going on here? In the following code, I expect the printed result to be: DEBUG: frank's last name is burns. Instead, what I get is: DEBUG: frank's last name is...
220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
137
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very...
12
by: Dario | last post by:
The following simple program behaves differently in Windows and Linux . #include <stdexcept> #include <iostream> #include <string> using namespace std; class LogicError : public logic_error {...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
47
by: Neal | last post by:
Patrick Griffiths weighs in on the CSS vs table layout debate in his blog entry "Tables my ass" - http://www.htmldog.com/ptg/archives/000049.php . A quite good article.
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
8
by: Midnight Java Junkie | last post by:
Dear Colleagues: I feel that the dumbest questions are those that are never asked. I have been given the opportunity to get into .NET. Our organization has a subscription with Microsoft that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.