Jump to content

[SOLVED] -> versus =


damianjames

Recommended Posts

This is an embarrassing question, but I can't seem to search for it and find anything. (when I search for "PHP ->" Google ignores the ->, and PHP.net wants me to give at least 3 characters in a search).  So obviously I'm new at PHP, and I'd like either a quick explanation of when and why to use -> with a variable instead of =, or at least a primer I can read.

 

I appreciate your responses, sorry if this is a bit too newbie.

Link to comment
Share on other sites

-> is a reference to a method or vairable within an object, and = defines a variable.

 

<?php

$foo = 'bar';

$object = new someClass;

$object->methodInSomeClass( $foo );

$foo = $object->varInSomeClass;

echo $foo;

class someClass {

    public $varInSomeClass = 'Hello World';

    public function methodInSomeClass( $param ) {

        echo $param . '<br>';

    }

}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.