View Full Version : whats the & in php?
VistaBoy
04-10-2008, 02:55 PM
Okay say i have this in a class
$this->db = &$db;
whats the & do??
Wayne
04-10-2008, 03:02 PM
Read this http://en.wikipedia.org/wiki/%26#Computing
Invent
04-10-2008, 03:11 PM
It makes $this->db a reference of $db.
Source
04-10-2008, 03:16 PM
I think the best way to explain it is, its an alias. A nickname to a person if you will.
Calon
04-10-2008, 03:29 PM
Try learning the operators.
http://uk2.php.net/operators
Dentafrice
04-10-2008, 05:57 PM
It's called references, although I like to refer to them as aliases (don't ask ;P).
It basically means this:
$a = 1;
$b = $a;
When you set $b to be $a, it sets the value of $b to 1, until you change it.
When you do this:
$a = 1;
$b = & $a;
$a = 2; // means $b will also be 2, as it is a reference of $a.
$b is just another name for $a.
I didn't know this.
thanks :D
VistaBoy
04-10-2008, 09:23 PM
It's called references, although I like to refer to them as aliases (don't ask ;P).
It basically means this:
$a = 1;
$b = $a;
When you set $b to be $a, it sets the value of $b to 1, until you change it.
When you do this:
$a = 1;
$b = & $a;
$a = 2; // means $b will also be 2, as it is a reference of $a.
$b is just another name for $a.
Thank you i have done it to my scripts as with out it, it never worked now i know why i am happy :D
Hypertext
05-10-2008, 02:15 AM
It's called references, although I like to refer to them as aliases (don't ask ;P).
It basically means this:
$a = 1;
$b = $a;
When you set $b to be $a, it sets the value of $b to 1, until you change it.
When you do this:
$a = 1;
$b = & $a;
$a = 2; // means $b will also be 2, as it is a reference of $a.
$b is just another name for $a.
Ah, that clears things up, thanks.
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.