RE: How to access any function of a any class?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>
> -----Original Message-----
> From: pf@xxxxxxxxxxxxxxxxxxxxxxxx [mailto:pf@xxxxxxxxxxxxxxxxxxxxxxxx]
> Sent: Wednesday, March 16, 2005 2:27 PM
> To: php-general@xxxxxxxxxxxxx
> Subject:  How to access any function of a any class?
>
> Hello.
> Please consider this:
>
> class A {
> [snip]
>
> class B {
> [snip]
>
> class Container{
>   function Container(){
> [snip]
>
> $MyOBJ=new Container();
>
>
>> The problem is that "sometimes" member functions and variables can be
>> reached this way, but sometimes not (mainly variables or file pointers)
>> depending WHEN you create the object and when (for example) you create a
>> file pointer inside some class.
>
>> What I want to do is to be able to use any function of any class from
>> any
>> function of any class.
>
> That´s not possible if You wanna do _entirely_ OOPD programming. You can
> let B inherits from A and let Container inherits from B then an instance
> of Container will contain all functions, but a instance from A cannot call
> the function Container. Read more here:
> http://dk2.php.net/manual/en/keyword.extends.php

I'm sorry Kim, but it is possible, I've made a web hosting control panel
using entirely this approach and it is working very well for months now. A
demo: http://cpdemo.sistemasdinamicos.com.ar/

Just a snip of the class that creates a domain (any other class uses
exactle the same constructor):

class CDominio
{

	function CDominio(&$cont)
	{
		$this->ct= &$cont;
		$this->classname=get_class($this);
	}
	#
	#
	function CreateDomain($d,$SecLevel="1",$UserType="1") /*UserType 1)
reseller 2) user*/
	{
		$d=trim($d);
		$new_user_id=$this->ct->syf->user_uniqid(2);
		if(!$this->ct->db->query("insert into dominios (dominio, user_id) values
('$d', '$new_user_id')")) {
			die(gettext("Unable to insert new domain"));
		}
		//Si el usuario que crea es un reseller, tomamos la info de su PC
		if($this->ct->cr->sess->user['perms'] == "reseller") {


Look how I can access any member using the container class (which has a
reference to every class used in the script)

For ex: $this->ct->db->query...
The db class contained by ct (the container)
or
$this->ct->cr->sess
the cr object (another container [contained in the ct] that contains all
the core classes=session, authentication, security)

But, this approach works ok statically or in single scripts, but I have
problems, for example with this:

class A, B and the Container the same as before

and thne you add (for example) a socket pointer to the Container (from the
main script or from B), then you if  you do
is_resource($this->Container->SocketPointer) from A the poiter is not
there.
It seems that "sometimes" it works as expected and sometimes not.
It do work when you add the class to the container after you add the
pointer to it (I've found this today)

Googling I also found that I should first create tmp copies of the objects
before adding them to the container class (I was trying to find the link
to post it here, but forgot the query I've made).

Perhaps I should try php5, I was told it has MUCH BETTER objects.

Thanks for your answer.

>
> You could just drop the idea of several classes or the OOP programming (I
> removed the D on purpose due to the bad design ;-)
>
> --
> Med venlig hilsen / best regards
> ComX Networks A/S
> Kim Madsen
> Systemudvikler/Systemdeveloper
> Naverland 31
>
> DK-2600 Glostrup
> www.comx.dk
> Telefon: +45 70 25 74 74
> Telefax: +45 70 25 73 74
> E-mail: km@xxxxxxx
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Hernán Marino

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux