Jump to content


Photo

What the heck is a ->


  • This topic is locked This topic is locked
8 replies to this topic

#1 famous58

famous58
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 02 March 2006 - 10:59 PM

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.
I'm trying, really I am.

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 03 March 2006 - 02:04 AM

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

#3 neylitalo

neylitalo
  • Staff Alumni
  • Advanced Member
  • 1,854 posts
  • LocationMichigan, USA

Posted 03 March 2006 - 03:25 AM

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:

<?php

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

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

    public function getLastName()
    {
        return $this->lastName;
    }
}
?>

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

When referencing methods or properties inside 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. :)

http://nealylitalo.net - My personal website, and home of The Netizen's Journal.

#4 helpmeplease2

helpmeplease2
  • Members
  • PipPipPip
  • Advanced Member
  • 87 posts

Posted 03 March 2006 - 05:32 AM

[!--sizeo:3--][span style=\"font-size:12pt;line-height:100%\"][!--/sizeo--]Simpler[!--sizec--][/span][!--/sizec--]
adj. sim┬Ěpler
Not involved or complicated; easy

#5 famous58

famous58
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 03 March 2006 - 04:29 PM

[!--quoteo(post=351228:date=Mar 2 2006, 07:25 PM:name=neylitalo)--][div class=\'quotetop\']QUOTE(neylitalo @ Mar 2 2006, 07:25 PM) View Post[/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?

I'm trying, really I am.

#6 neylitalo

neylitalo
  • Staff Alumni
  • Advanced Member
  • 1,854 posts
  • LocationMichigan, USA

Posted 03 March 2006 - 07:48 PM

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
http://www.domain.com/index.php?a=1&b=2
then put this code into index.php to get the data from that URL:

<?php

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

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

?>

http://nealylitalo.net - My personal website, and home of The Netizen's Journal.

#7 famous58

famous58
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 03 March 2006 - 07:56 PM

[!--quoteo(post=351408:date=Mar 3 2006, 11:48 AM:name=neylitalo)--][div class=\'quotetop\']QUOTE(neylitalo @ Mar 3 2006, 11:48 AM) View Post[/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
http://www.domain.com/index.php?a=1&b=2
then put this code into index.php to get the data from that URL:

<?php

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

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

?>
[/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) View Post[/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
http://www.domain.com/index.php?a=1&b=2
then put this code into index.php to get the data from that URL:

<?php

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

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

?>
[/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?
I'm trying, really I am.

#8 dinardo01

dinardo01
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 13 October 2006 - 01:51 PM


What is a =>

#9 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 13 October 2006 - 02:22 PM

Blimmy! How old is this!

Any way please read this FAQ

Thread closed.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users