double arrow , single-arrow and now multi arrow ????

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

double arrow , single-arrow and now multi arrow ????

Post by gautamz07 »

hey guys i have been learning PHP for a few days now : i have a difficulty though :

checkout the below script :

Code: Select all

<?php
ini_set("display_errors","1");
ERROR_REPORTING(E_ALL);

include_once('universal_connect.php');
class CreateTable
{
	private $tableMaster;
	private $hookup;
	private $sql;
	
	public function __construct()
	{
		$this->tableMaster="gautam";
		$this->hookup=UniversalConnect::doConnect();
	
		$drop = "DROP TABLE IF EXISTS $this->tableMaster";
	
		if($this->hookup->query($drop) === true)
		{
			printf("Old table %s has been dropped.<br/>",$this->tableMaster);
		}

		$this->sql = "CREATE TABLE $this->tableMaster (
			id SERIAL,
			name NVARCHAR(30),
			email NVARCHAR(36),
			lang NVARCHAR(10),
			PRIMARY KEY(id)
			)";
	
		if($this->hookup->query($this->sql) === true)
		{
			printf("Table $this->tableMaster has been created successfully.<br/>");
		}


		$this->hookup->close();
	}
}

$worker=new CreateTable();

?>
now when i see something like :

Code: Select all

a => "LOL"
or

Code: Select all

$instance = new person();

$instance->get_person_name();
i am comfortable with the syntex , but when i see something like :

Code: Select all

$a->$b->$c ; 
i really get horrified !!! when are such constructs really used ??

can somebody really be kind enuf to point me to a documentation or some example .

This has been haunting me for quite a while now .

Thanks .

Gautam.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: double arrow , single-arrow and now multi arrow ????

Post by requinix »

Code: Select all

$this->hookup->close();
What's so scary about it? It's just using another arrow: do $this->hookup first, then ->close() on whatever the previous thing was. You can chain them together with as many as you want too.
It's the exact same as writing

Code: Select all

$temp = $this->hookup;
$temp->close();
but without having to use that "$temp" variable.

Now I'm sure it was accidental but while

Code: Select all

$a->$b->$c
does use two arrows, putting those extra $s in there changes how the arrow works by a little. Nothing to worry about now - just don't put $s with the property names.
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

Re: double arrow , single-arrow and now multi arrow ????

Post by gautamz07 »

Thank you ! :)
Post Reply