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
https://forums.phpfreaks.com/topic/116648-solved-gt-versus/
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
https://forums.phpfreaks.com/topic/116648-solved-gt-versus/#findComment-599771
Share on other sites

Archived

This topic is now archived and is 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.