----- Original Message ----- 
From: "Wade Smart"

listgroups08 wrote:
> Hi all,
>         I am playing with classes for the first time and I am at a bit of a
> loss in php.
>
> How do I access the properties/functions of the parent class from sub
> function?
>
> And how do I register resources into the scope of the parent class?
>
> For example if I have -
> class Data_Base
>   {
>   var $server;
>   var $username;
>   var $password;
>   function Data_Base
>     {
>     $this->server = "127.0.01";
>     $this->username = "username";
>     $this->password = "password";
>     }
>   function Connect
>     {
>     $handle = mysql_connect($server, $username, $password);
>      }
>   }
>
> How do I get $server etc from the root scope of Data_Base?
>
> And how do I register $handle into the global scope of Data_Base without
> registering it into the global scope of PHP?
>
> ie - does var $server create a scope that is accessible in sub functions or
> is it just in the root scope?
>
> Thanks, Robert.

20081007 1639 GMT-6

Im just starting with objects myself so this might not be right.
But from the reading I was doing today, if you want the $handle you
would do "return $handle" just like a normal function.

Wade
------------------------------------

Hi Wade,
              I would have thought that using return in a sub function will 
return the the resource into the global php environment 
but only with assigment ie -

class Data_Base
  {
  function connect
    {
    $handle = mysql_connect("127.0.0.1", "username", "password");
    return $handle;
    }
  }
$database = new Data_Base;
$my_handle = $database->connect;

Am I missing something here? Can objects be created without classes? I haven't 
seen anything else in php that will prototype.

I don't want things like a mysql resource handles in the global scope of php. I 
want to completely abstract the database so that 
only the data and validation is returned. And things like mysql resource 
handles only exist in the scope of the class object.

ie -
foreach($database->table->field as $this_field)
  {
  $result = $this_field->is_valid($submited_data);
  if(!$result === TRUE)
    {
    $re_enter = TRUE;
    $error_message .= $result;
    }
  }
if($re_enter)
  {
  echo("The following information is not valid, please re-enter\n" . 
$error_mesage)
  }

I don't know if this helps but in javascript ....

onmouseover = "dosomething;"
is completely different to -
onmouseover = "dosomething();"

The first registers the existing form of the function dosomething into the 
scope of the mouseover event. So it is like class in php.
However the second executes the function dosomething in the document scope when 
the mouseover event is trigered. So it is like 
function in php.

So in the first, 'this' represents the mouseover event and is NOT in the 
document scope.
However in the second, 'this' represents the element that is moused over and IS 
in the document scope.

In Javascript you can do this -
function dosomething(element)
  {
  element.src = "new_image";
  }
onmouseover = "dosomething(this);"
witch works in the document scope like php functions return variables into the 
php environment scope.

or you can do this
function dosomething()
  {
  this.parent.src = "new_image";
  }
onmouseover = "dosomething;"
The above is not in the document scope but is able to gain access to the parent 
scope and inject a function into the parent scope. 
Because the onmouseover is a trigered event that is trigered by an element in 
the document scope then 'this.parent' is in the 
docuemnt scope even when the event assigned function "dosomething" is NOT.

I want to do the same in php.

I want to be able to access the parent scope of a class and from there I can 
access the scope of class subfunctions but I want to do 
this without entering the global scope of the php environment.

Clear as mud? :)

Thanks, Robert. 

Reply via email to