Jump to content

What the heck is a ->


famous58

Recommended Posts

So I asked a rather lengthy question [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=87298\" target=\"_blank\"]here[/a] and am thinking it might be a bit much.

So I thought I would start a little simpler (is that a word?).

What the heck is this little deal ->. I see it a lot in giant scripts that I didn't and couldn't write, and I'm thinking this might be something I want to learn about. I tried doing a search for that little dealy bob but of course nothing comes up. And seeing how I don't know what it's called it is kinda difficult to get info on what it is/does.

T.I.A. for any insight on this.
Link to comment
Share on other sites

That operator is used with classes and object. I don't use them very often, so I can't give a simple explanation.

Take a look at [a href=\"http://us2.php.net/manual/en/ref.classobj.php\" target=\"_blank\"]http://us2.php.net/manual/en/ref.classobj.php[/a] and [a href=\"http://us2.php.net/manual/en/language.oop5.basic.php#language.oop5.basic.class\" target=\"_blank\"]http://us2.php.net/manual/en/language.oop5...op5.basic.class[/a]

Ken
Link to comment
Share on other sites

This is used in the following syntax:

$object->method(); (where method is the name of a function, and object is an instance of a class)
$object->property; (where property is a variable in a class - the OOP term is property)

ie:

[code]<?php

class person
{
    public function __construct()
    {
        $firstName = "John";
        $lastName = "Smith";
    }

    public function getFirstName()
    {
        return $this->firstName;
    }

    public function getLastName()
    {
        return $this->lastName;
    }
}
?>[/code]

That's an example of a [i]class[/i]. $firstName and $lastName are [i]properties[/i] of the class, and getFirstName() and getLastName() are [i]methods[/i] of the class.

When referencing methods or properties [i]inside[/i] their containing class (look at getFirstName and getLastName), you use $this to reference the class. It's always an object on the left and a method or property on the right of the ->.

Hope I didn't confuse you. :)
Link to comment
Share on other sites

[!--quoteo(post=351228:date=Mar 2 2006, 07:25 PM:name=neylitalo)--][div class=\'quotetop\']QUOTE(neylitalo @ Mar 2 2006, 07:25 PM) [snapback]351228[/snapback][/div][div class=\'quotemain\'][!--quotec--]

Hope I didn't confuse you. :)
[/quote]

Not completely. How would I then use this method to pull info from an api return url? If I know the variables that are returned could I build a function that takes the info from a URL and then pull elements from what is returned. Does that make sense?
Link to comment
Share on other sites

ah... you won't need classes to do this.

All you need to do this is access the $_GET array. Check this out.

If you're accessing this URL [code]http://www.domain.com/index.php?a=1&b=2[/code] then put this code into index.php to get the data from that URL:

[code]<?php

$a = $_GET['a'];
$b = $_GET['b'];

echo $a; //will echo 1
echo $b; //will echo 2

?>[/code]
Link to comment
Share on other sites

[!--quoteo(post=351408:date=Mar 3 2006, 11:48 AM:name=neylitalo)--][div class=\'quotetop\']QUOTE(neylitalo @ Mar 3 2006, 11:48 AM) [snapback]351408[/snapback][/div][div class=\'quotemain\'][!--quotec--]
ah... you won't need classes to do this.

All you need to do this is access the $_GET array. Check this out.

If you're accessing this URL [code]http://www.domain.com/index.php?a=1&b=2[/code] then put this code into index.php to get the data from that URL:

[code]<?php

$a = $_GET['a'];
$b = $_GET['b'];

echo $a; //will echo 1
echo $b; //will echo 2

?>[/code]
[/quote]

Sa-Weet. It was worth getting out of bed today, I did gone and learnt something! Thanks!

[!--quoteo(post=351408:date=Mar 3 2006, 11:48 AM:name=neylitalo)--][div class=\'quotetop\']QUOTE(neylitalo @ Mar 3 2006, 11:48 AM) [snapback]351408[/snapback][/div][div class=\'quotemain\'][!--quotec--]
ah... you won't need classes to do this.

All you need to do this is access the $_GET array. Check this out.

If you're accessing this URL [code]http://www.domain.com/index.php?a=1&b=2[/code] then put this code into index.php to get the data from that URL:

[code]<?php

$a = $_GET['a'];
$b = $_GET['b'];

echo $a; //will echo 1
echo $b; //will echo 2

?>[/code]
[/quote]

Wait, maybe I spoke too soon. What if I don't have access to index.php cause it's on someone else's server (API)? So, I need to create a page that accesses a URL, get's the info from that URL and puts it into my page?
Link to comment
Share on other sites

  • 7 months later...
Guest
This topic is now closed to further replies.
×
×
  • Create New...

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.