views:

13

answers:

1

This is sample of my code.

class SomeClass extends SomeOtherClass
{

function __construct($input)
{
parent::__construct($input);
$this->conn = new mysqli('a','b','c','d');
}

function getConnection()
{
return &$this->conn;
}

}

My main object is that i want to return the MySQLi connection by referencing it instead of creating another MySQLi class.

A: 

It's:

function &getConnection()
{
   return $this->conn;
}

and when calling:

$conn = &$instance->getConnection();

That's how to return variables by reference in general, but for resource type variables you don't need to.

aularon
Dada
I edited the question for more clarification, and yes php is weird : )Don't forget to mak accepted answers as accepted.
aularon
I was waiting for the time limit to pass to accept as answer. Thanks i accepted.
Dada