|
Posted by on 08/02/05 18:21
lol, fellas...
resourse = resource
sense = cents
anyway...there should be no error at all. you have a variable that points to
an instance of an object. you then point it to a new instance of that
object. of course the resource will be different as it points to a new
connection. the previous instance, if nothing else points to it or if php
determines that it is otherwise unreachable (don't know if php uses garbage
collection or reference counting), will have gone out of scope and
will/should be destroyed by php.
without this understanding, the question asked, "can two objects have the
same name" seems reasonable. technically though, the object *always* has the
same name. a variable by *any* name can point to an *instance* of an object
but can only do so one at a time...unless that variable is an array.
i hope that makes *sense* and helps you out. ;^)
me
"Tony Mays" <tony@nospam.com> wrote in message
news:r3FHe.168273$go.134443@fed1read05...
| run the following code and see what you get:
|
| $connTest = new connDb;
| $connTest->Conn('localhost','root', '');
|
| echo $connTest.<br />;
|
| $res1 = $connTest->resourse;
| $connTest = new connDb;
| $connTest->Conn('localhost','mike', '');
|
| echo $connTest.<br />;
|
| $res2 = $connTest->resourse;
| echo $res1.<br />;
| echo $res2.<br />;
|
|
| sorry I just don't have the time to test this at this time but thought I
| would put my two sense worth in ... hope it helps. good luck
|
| tm
|
|
|
|
| None wrote:
|
| > Hello,
| > I know these seem simple to most but...
| > I created a simple connection class:
| >
| > Class connDb{
| > public $resourse;
| > function Conn($host,$user,$pass){
| > $link = mysql_connect($host, $user, $pass);
| > if (!$link) {
| > die('Could not connect: ' . mysql_error());
| > }
| > $this->resourse=$link;
| > mysql_select_db("test2");
| >
| > When I go to create 2 objects with the same name:
| > $connTest = new connDb;
| > $connTest->Conn('localhost','root', '');
| > echo $connTest->resourse;
| > $connTest = new connDb;
| > $connTest->Conn('localhost','mike', '');
| > echo $connTest->resourse;
| >
| > I DO NOT get an error I just get 2 different resourcce IDs.Can you have
| > two objects with the same name?
| > Thanks
| > Mike
|
Navigation:
[Reply to this message]
|