Re: [PHP] Re: PHP class question

2009-05-21 Thread Nathan Rixham

Shawn McKenzie wrote:

Shawn McKenzie wrote:

Peter van der Does wrote:

On Thu, 21 May 2009 14:08:11 -0500
Shawn McKenzie  wrote:



This doesn't make sense.  You say "class A needs to be extended with
another class", however what you show below is "class A extending
framework_class".


I worded it wrong, I apologize.
Class A needs to be an extension of the framework class.


Well I guess from my point of view there are several ways depending upon
the requirements.  Others that are better with OOP will chime in I'm sure.

This I'll get flamed for, but you can use one instance of core as a global:

class A extends framework_class {
  var $core;

  function A() {
$this->core =& $GLOBALS['core'];
$this->core->go();
  }
}

//in global scope in bootstrap or whatever
$core = new core();

Along the same lines but more OOP and without globals, maybe use a
registry class and store core in the registry. This also uses one
instance of core:

class Registry {
protected $_objects = array();

function set($name, &$object) {
$this->_objects[$name] =& $object;
}

function &get($name) {
return $this->_objects[$name];
}
}

class A extends framework_class {
  var $core;

  function A(&$registry) {  //dunno if you need a reference here or not
$this->core = $registry->get('core');
$this->core->go();
  }
  //i guess you could also pass in core, but registry will give you all
objects in the registry
  //function A(&core) {
//$this->core = $core;
//$this->core->go();
  //}
}

//this is in your bootstrap or whatever
$core = new core();
$registry = new registry();
$registry->set('core', $core);

Or, if you don't need an object, call it statically:

class A extends framework_class {

  function A() {
core::go();
  }
}



I guess you could always do a singleton so that you always have the same
instance.  Add something like this to the core class (not tested):

static $_instance;

function getInstance() {
if(self::$_instance === null) {
self::$_instance = new self();
}
return self::$_instance;
}

Then you can do:

class A extends framework_class {
   var $core;

   function A() {
 $this->core = core::getInstance();
 $this->core->go();
   }
 }



bullseye, static is the way to approach when you only need a single instance

however you don't always need to include a referent to the instance 
inside your class.. you can easily


core::getInstance()->go()
or
core::go()

and have class core store an instance of itself

class core {
  var $instance;
  function getInstance()

..etc - been so long since i touched php4

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



Re: [PHP] Re: PHP class question

2009-05-21 Thread Shawn McKenzie
Shawn McKenzie wrote:
> Peter van der Does wrote:
>> On Thu, 21 May 2009 14:08:11 -0500
>> Shawn McKenzie  wrote:
>>
>>
>>> This doesn't make sense.  You say "class A needs to be extended with
>>> another class", however what you show below is "class A extending
>>> framework_class".
>>>
>> I worded it wrong, I apologize.
>> Class A needs to be an extension of the framework class.
>>
> 
> Well I guess from my point of view there are several ways depending upon
> the requirements.  Others that are better with OOP will chime in I'm sure.
> 
> This I'll get flamed for, but you can use one instance of core as a global:
> 
> class A extends framework_class {
>   var $core;
> 
>   function A() {
> $this->core =& $GLOBALS['core'];
> $this->core->go();
>   }
> }
> 
> //in global scope in bootstrap or whatever
> $core = new core();
> 
> Along the same lines but more OOP and without globals, maybe use a
> registry class and store core in the registry. This also uses one
> instance of core:
> 
> class Registry {
> protected $_objects = array();
> 
> function set($name, &$object) {
> $this->_objects[$name] =& $object;
> }
> 
> function &get($name) {
> return $this->_objects[$name];
> }
> }
> 
> class A extends framework_class {
>   var $core;
> 
>   function A(&$registry) {  //dunno if you need a reference here or not
> $this->core = $registry->get('core');
> $this->core->go();
>   }
>   //i guess you could also pass in core, but registry will give you all
> objects in the registry
>   //function A(&core) {
> //$this->core = $core;
> //$this->core->go();
>   //}
> }
> 
> //this is in your bootstrap or whatever
> $core = new core();
> $registry = new registry();
> $registry->set('core', $core);
> 
> Or, if you don't need an object, call it statically:
> 
> class A extends framework_class {
> 
>   function A() {
> core::go();
>   }
> }
> 

I guess you could always do a singleton so that you always have the same
instance.  Add something like this to the core class (not tested):

static $_instance;

function getInstance() {
if(self::$_instance === null) {
self::$_instance = new self();
}
return self::$_instance;
}

Then you can do:

class A extends framework_class {
   var $core;

   function A() {
 $this->core = core::getInstance();
 $this->core->go();
   }
 }

-- 
Thanks!
-Shawn
http://www.spidean.com

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



Re: [PHP] Re: PHP class question

2009-05-21 Thread Shawn McKenzie
Peter van der Does wrote:
> On Thu, 21 May 2009 14:08:11 -0500
> Shawn McKenzie  wrote:
> 
> 
>> This doesn't make sense.  You say "class A needs to be extended with
>> another class", however what you show below is "class A extending
>> framework_class".
>>
> 
> I worded it wrong, I apologize.
> Class A needs to be an extension of the framework class.
> 

Well I guess from my point of view there are several ways depending upon
the requirements.  Others that are better with OOP will chime in I'm sure.

This I'll get flamed for, but you can use one instance of core as a global:

class A extends framework_class {
  var $core;

  function A() {
$this->core =& $GLOBALS['core'];
$this->core->go();
  }
}

//in global scope in bootstrap or whatever
$core = new core();

Along the same lines but more OOP and without globals, maybe use a
registry class and store core in the registry. This also uses one
instance of core:

class Registry {
protected $_objects = array();

function set($name, &$object) {
$this->_objects[$name] =& $object;
}

function &get($name) {
return $this->_objects[$name];
}
}

class A extends framework_class {
  var $core;

  function A(&$registry) {  //dunno if you need a reference here or not
$this->core = $registry->get('core');
$this->core->go();
  }
  //i guess you could also pass in core, but registry will give you all
objects in the registry
  //function A(&core) {
//$this->core = $core;
//$this->core->go();
  //}
}

//this is in your bootstrap or whatever
$core = new core();
$registry = new registry();
$registry->set('core', $core);

Or, if you don't need an object, call it statically:

class A extends framework_class {

  function A() {
core::go();
  }
}

-- 
Thanks!
-Shawn
http://www.spidean.com

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



Re: [PHP] Re: PHP class question

2009-05-21 Thread Peter van der Does
On Thu, 21 May 2009 14:08:11 -0500
Shawn McKenzie  wrote:


> 
> This doesn't make sense.  You say "class A needs to be extended with
> another class", however what you show below is "class A extending
> framework_class".
> 

I worded it wrong, I apologize.
Class A needs to be an extension of the framework class.

-- 
Peter van der Does

GPG key: E77E8E98
IRC: Ganseki on irc.freenode.net
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Jabber ID: pvanderd...@gmail.com

GetDeb Package Builder
http://www.getdeb.net - Software you want for Ubuntu

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



[PHP] Re: PHP class question

2009-05-21 Thread Shawn McKenzie
Peter van der Does wrote:
> I have the following situation.
> 
> I wrote some software and split it up into functionality:
> 
> class core {
>   function go{
>   }
> }
> 
> class A extends core {
>   // PHP4 constructor
>   function A {
> $this->go();
>   }
> 
> }
> 
> class B extends core {
> }
> 
> In core I define functions and variables that are to be used
> through out my program and to address those functions/variables I just
> use $this-> .
> 
> Now I ran into a situation where class A needs to be extended with
> another class. This is not my choice, it's part of a framework I have
> to use.

This doesn't make sense.  You say "class A needs to be extended with
another class", however what you show below is "class A extending
framework_class".

Show your classes and we can help I think.

> Currently I solved this by doing this:
> 
> class A extends framework_class {
>   $var core;
> 
>   // PHP4 constructor
>   function A {
> $this->core = new core();
> $this->core->go();
>   }
> }
> 
> The question I have, is this a good solution, is it the only solution
> or are there different ways to tackle this?
> As you might see it needs to run in PHP4.
> 

I'm sure there are.  This doesn't look right to me, but I'm confused by
your examples.

-- 
Thanks!
-Shawn
http://www.spidean.com

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



[PHP] Re: PHP class question

2009-05-21 Thread Nathan Rixham

Peter van der Does wrote:

I have the following situation.

I wrote some software and split it up into functionality:

class core {
  function go{
  }
}

class A extends core {
  // PHP4 constructor
  function A {
$this->go();
  }

}

class B extends core {
}

In core I define functions and variables that are to be used
through out my program and to address those functions/variables I just
use $this-> .

Now I ran into a situation where class A needs to be extended with
another class. This is not my choice, it's part of a framework I have
to use.

Currently I solved this by doing this:

class A extends framework_class {
  $var core;

  // PHP4 constructor
  function A {
$this->core = new core();
$this->core->go();
  }
}

The question I have, is this a good solution, is it the only solution
or are there different ways to tackle this?
As you might see it needs to run in PHP4.



has to extend? if it *has* to extend then you have no choice, but you 
may want to look up on class inheritance, specifically inheritance vs 
composition.


also the "isa" / "hasa" rule /should/ always apply.

which one of the following is true
1: A isa framework_class_name
2: A hasa framework_class_name

if it's 1 then you extend
if it's 2 then A should contain an instance of framework_class

eg:
class A
{
  var $framework_class = new framework_class_name();
}

you can also always proxy the methods you need.

all in, this appears to be a design pattern issue and really can't help 
any more unless you give some specifics. (like the source of your 
classes and the framework class you need to extend)


regards,

nathan

incidentally, I play inheritance vs composition as game with my 4 year 
old son, and he's really good - the untainted mind of a child can easily 
solve things us older types find more complex.

eg: car isa wheel, car hasa wheel

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



[PHP] PHP class question

2009-05-21 Thread Peter van der Does
I have the following situation.

I wrote some software and split it up into functionality:

class core {
  function go{
  }
}

class A extends core {
  // PHP4 constructor
  function A {
$this->go();
  }

}

class B extends core {
}

In core I define functions and variables that are to be used
through out my program and to address those functions/variables I just
use $this-> .

Now I ran into a situation where class A needs to be extended with
another class. This is not my choice, it's part of a framework I have
to use.

Currently I solved this by doing this:

class A extends framework_class {
  $var core;

  // PHP4 constructor
  function A {
$this->core = new core();
$this->core->go();
  }
}

The question I have, is this a good solution, is it the only solution
or are there different ways to tackle this?
As you might see it needs to run in PHP4.

-- 
Peter van der Does

GPG key: E77E8E98
IRC: Ganseki on irc.freenode.net
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Jabber ID: pvanderd...@gmail.com

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



Re: [PHP] Class question

2006-09-15 Thread Roger Helgesen

What does "$this->A(); "" do ?(in constructor of class B)
does it make another instance of class A, and if not why do I have to 
parse vars to the A constructor ($this->A($var1,$var2))?.

I dont think that is what I want.
A can have many instances of B. B can have many instances of C.


 A
   B   B   B
  B

    

Should not a instanse(object) of class B bee able to request av var of 
the calling  object (class A)?


Sorry about this stupid questions, I'm not a coder.
Thomas Munz wrote:

Use 'extends' syntax for sub classes

class A {
  var $some_var;
   var $class_B;
  function A(){
$this->class_B = new B();
$this->some_var=2;
  }
}

class B extends A {
  var $class_C;
  function B(){
$this->A();
$this->class_C = new C();
   //  $this->some_var= some_var_from_class_A; <-- $this->some_var 
contains the value allready
  }
}

class C extends A {
  function C(){
$this->A();
// $this->some_var= some_var_from_class_A; <-- $this->some_var 
contains the value allready
  }
}

on Friday 15 September 2006 11:01, Roger Helgesen wrote:
  

I have 3 classes, CLASS A,B and C

class A {
  var $some_var;
   var $class_B;
  function A(){
$this->class_B = new B();
$this->some_var=2;
  }
}

class B {
  var $some_var;
   var $class_C;
  function B(){
$this->class_C = new C();
$this->some_var= some_var_from_class_A;
  }
}

class C {
  var $some_var;

  function C(){
$this->some_var= some_var_from_class_A;
  }
}



How can class B and C get the value of $some_var_class_A without using
"$this->class_B = new B($some_var);"


roger helgesen



  


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



Re: [PHP] Class question

2006-09-15 Thread Andrei

Well in this example it will get to an infinite loop, but anyway like
Thomas said you must check into extending classes.

Andy

Thomas Munz wrote:
> Use 'extends' syntax for sub classes
> 
> class A {
>   var $some_var;
>var $class_B;
>   function A(){
> $this->class_B = new B();
> $this->some_var=2;
>   }
> }
> 
> class B extends A {
>   var $class_C;
>   function B(){
> $this->A();
> $this->class_C = new C();
>//  $this->some_var= some_var_from_class_A; <-- 
> $this->some_var contains the value allready
>   }
> }
> 
> class C extends A {
>   function C(){
> $this->A();
> // $this->some_var= some_var_from_class_A; <-- 
> $this->some_var contains the value allready
>   }
> }
> 

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



Re: [PHP] Class question

2006-09-15 Thread Thomas Munz
Use 'extends' syntax for sub classes

class A {
  var $some_var;
   var $class_B;
  function A(){
$this->class_B = new B();
$this->some_var=2;
  }
}

class B extends A {
  var $class_C;
  function B(){
$this->A();
$this->class_C = new C();
   //  $this->some_var= some_var_from_class_A; <-- $this->some_var 
contains the value allready
  }
}

class C extends A {
  function C(){
$this->A();
// $this->some_var= some_var_from_class_A; <-- $this->some_var 
contains the value allready
  }
}

on Friday 15 September 2006 11:01, Roger Helgesen wrote:
> I have 3 classes, CLASS A,B and C
>
> class A {
>   var $some_var;
>var $class_B;
>   function A(){
> $this->class_B = new B();
> $this->some_var=2;
>   }
> }
>
> class B {
>   var $some_var;
>var $class_C;
>   function B(){
> $this->class_C = new C();
> $this->some_var= some_var_from_class_A;
>   }
> }
>
> class C {
>   var $some_var;
>
>   function C(){
> $this->some_var= some_var_from_class_A;
>   }
> }
>
>
>
> How can class B and C get the value of $some_var_class_A without using
> "$this->class_B = new B($some_var);"
>
>
> roger helgesen

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



[PHP] Class question

2006-09-15 Thread Roger Helgesen

I have 3 classes, CLASS A,B and C

class A {
 var $some_var;
  var $class_B;
 function A(){
   $this->class_B = new B();
   $this->some_var=2;
 }
}

class B {
 var $some_var;
  var $class_C;
 function B(){
   $this->class_C = new C();
   $this->some_var= some_var_from_class_A;
 }
}

class C {
 var $some_var;

 function C(){

   $this->some_var= some_var_from_class_A;
 }
}



How can class B and C get the value of $some_var_class_A without using 
"$this->class_B = new B($some_var);"



roger helgesen

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



Re[2]: [PHP] PHP - class question

2002-08-14 Thread Tom Rogers

Hi,

Thursday, August 15, 2002, 5:17:00 AM, you wrote:
MA> Well, I actually have a full db class which has a connect  and close method
MA> as well as query, fetch_array, etc... What I really want to know is how to
MA> use the methods in my db class from another class (myclass for example)..

MA> Do I include the db class from the myclass constructor and then set a
MA> myclass variable = to the db object?

MA> ie.

MA> class my_class {
MA> var $db;

MA> function my_class() {
MA> include('class_database.php');

MA> $this->db = new database;
MA> }

MA> ...
MA> }

MA> or is there a differnet or better way?

I set up interclass communication by having a global array for
references like this:
t;
  }
}

class b {
  var $a; //class a holder
  //constructor
  function b(){
   global $classes;
   //if the class already exists use it...
   if(is_object($classes['a'])){
  $this->a =& $classes['a'];
   }
   //otherwise create it...
   else{
  $this->a = new a();
   }
   $this->a->test();
  }
}
$a1 =& new a();
$a1->t = 'This is a test';
$b1 = new b();
?>
whether it is better depends on usage, but it should be good for a db
class so you only make the one connection :)



-- 
regards,
Tom


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




Re: [PHP] PHP - class question

2002-08-14 Thread Mark Armendariz

Do you know where I can find more info on how to use the  scope resolution
operator?

My searches aren't giving much (at leant not mcuh regarding php) and in the
manual, it only shows up momentarily as a note in the operators section...

Mark


"Nick Oostveen" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> If you are just trying to access a classes functions without creating an
> instance of it you're probably looking to use the scope resolution
operator
> ::.  For this to work all you have to do is ensure that the definition for
> the class you wish to use is included into the file containing the class
> you are trying to call the functions from.
>
> You would then call the functions as follows:
>
> ClassName::FunctionName();
>
> At 02:43 PM 8/14/2002 -0400, you wrote:
> >Hello,  To begin.. i'm new to the list...
> >
> >I'm trying to learn good practices in OOP based PHP.  I'm actually a bit
new
> >to OOP in general, but I've done quite a bit of reading and playing
around
> >with it in the past couple of months.
> >
> >What I'm trying to figure out is the proper way to call a class from a
> >class.  I dont mean by extending the class, but actaully just getting the
> >functions...
> >
> >For instance...
> >
> >I'm trying to connect to a Database (database class) from my gen_XML
class.
> >Do I include the database class in the gen_XML constructor?  Do I set a
> >gen_XML variable as a database object (i.e. $this->mydb)?
> >
> >I hope my question makes some sense...
> >
> >Your help is appreciated...
> >
> >Mark Armendariz
> >
> >
> >
> >--
> >PHP General Mailing List (http://www.php.net/)
> >To unsubscribe, visit: http://www.php.net/unsub.php
>



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




Re: [PHP] PHP - class question

2002-08-14 Thread Mark Armendariz

That seems more like what I'm looking for..

Thank you, Nick...

Mark



"Nick Oostveen" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> If you are just trying to access a classes functions without creating an
> instance of it you're probably looking to use the scope resolution
operator
> ::.  For this to work all you have to do is ensure that the definition for
> the class you wish to use is included into the file containing the class
> you are trying to call the functions from.
>
> You would then call the functions as follows:
>
> ClassName::FunctionName();
>
> At 02:43 PM 8/14/2002 -0400, you wrote:
> >Hello,  To begin.. i'm new to the list...
> >
> >I'm trying to learn good practices in OOP based PHP.  I'm actually a bit
new
> >to OOP in general, but I've done quite a bit of reading and playing
around
> >with it in the past couple of months.
> >
> >What I'm trying to figure out is the proper way to call a class from a
> >class.  I dont mean by extending the class, but actaully just getting the
> >functions...
> >
> >For instance...
> >
> >I'm trying to connect to a Database (database class) from my gen_XML
class.
> >Do I include the database class in the gen_XML constructor?  Do I set a
> >gen_XML variable as a database object (i.e. $this->mydb)?
> >
> >I hope my question makes some sense...
> >
> >Your help is appreciated...
> >
> >Mark Armendariz
> >
> >
> >
> >--
> >PHP General Mailing List (http://www.php.net/)
> >To unsubscribe, visit: http://www.php.net/unsub.php
>



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




Re: [PHP] PHP - class question

2002-08-14 Thread Mark Armendariz

Well, I actually have a full db class which has a connect  and close method
as well as query, fetch_array, etc... What I really want to know is how to
use the methods in my db class from another class (myclass for example)..

Do I include the db class from the myclass constructor and then set a
myclass variable = to the db object?

ie.

class my_class {
var $db;

function my_class() {
include('class_database.php');

$this->db = new database;
}

...
}

or is there a differnet or better way?

Thanks

Mark

"Steve Bradwell" <[EMAIL PROTECTED]> wrote in message
57A1618E7109D311A97D0008C7EBB3A10119EF03@KITCHENER">news:57A1618E7109D311A97D0008C7EBB3A10119EF03@KITCHENER...
> I would suggest you write a method (called mydb() for example) that
connects
> to your database, and if needed, call it from your constructor like:
> $this->mydb(); This way you can always reuse the method from other code.
>
> hth,
> Steve.
>
> -Original Message-
> From: Mark Armendariz [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 14, 2002 2:44 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] PHP - class question
>
>
> Hello,  To begin.. i'm new to the list...
>
> I'm trying to learn good practices in OOP based PHP.  I'm actually a bit
new
> to OOP in general, but I've done quite a bit of reading and playing around
> with it in the past couple of months.
>
> What I'm trying to figure out is the proper way to call a class from a
> class.  I dont mean by extending the class, but actaully just getting the
> functions...
>
> For instance...
>
> I'm trying to connect to a Database (database class) from my gen_XML
class.
> Do I include the database class in the gen_XML constructor?  Do I set a
> gen_XML variable as a database object (i.e. $this->mydb)?
>
> I hope my question makes some sense...
>
> Your help is appreciated...
>
> Mark Armendariz
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php



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




Re: [PHP] PHP - class question

2002-08-14 Thread Nick Oostveen

If you are just trying to access a classes functions without creating an 
instance of it you're probably looking to use the scope resolution operator 
::.  For this to work all you have to do is ensure that the definition for 
the class you wish to use is included into the file containing the class 
you are trying to call the functions from.

You would then call the functions as follows:

ClassName::FunctionName();

At 02:43 PM 8/14/2002 -0400, you wrote:
>Hello,  To begin.. i'm new to the list...
>
>I'm trying to learn good practices in OOP based PHP.  I'm actually a bit new
>to OOP in general, but I've done quite a bit of reading and playing around
>with it in the past couple of months.
>
>What I'm trying to figure out is the proper way to call a class from a
>class.  I dont mean by extending the class, but actaully just getting the
>functions...
>
>For instance...
>
>I'm trying to connect to a Database (database class) from my gen_XML class.
>Do I include the database class in the gen_XML constructor?  Do I set a
>gen_XML variable as a database object (i.e. $this->mydb)?
>
>I hope my question makes some sense...
>
>Your help is appreciated...
>
>Mark Armendariz
>
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php


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




RE: [PHP] PHP - class question

2002-08-14 Thread Steve Bradwell

I would suggest you write a method (called mydb() for example) that connects
to your database, and if needed, call it from your constructor like:
$this->mydb(); This way you can always reuse the method from other code.

hth,
Steve.

-Original Message-
From: Mark Armendariz [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 14, 2002 2:44 PM
To: [EMAIL PROTECTED]
Subject: [PHP] PHP - class question


Hello,  To begin.. i'm new to the list...

I'm trying to learn good practices in OOP based PHP.  I'm actually a bit new
to OOP in general, but I've done quite a bit of reading and playing around
with it in the past couple of months.

What I'm trying to figure out is the proper way to call a class from a
class.  I dont mean by extending the class, but actaully just getting the
functions...

For instance...

I'm trying to connect to a Database (database class) from my gen_XML class.
Do I include the database class in the gen_XML constructor?  Do I set a
gen_XML variable as a database object (i.e. $this->mydb)?

I hope my question makes some sense...

Your help is appreciated...

Mark Armendariz



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

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




[PHP] PHP - class question

2002-08-14 Thread Mark Armendariz

Hello,  To begin.. i'm new to the list...

I'm trying to learn good practices in OOP based PHP.  I'm actually a bit new
to OOP in general, but I've done quite a bit of reading and playing around
with it in the past couple of months.

What I'm trying to figure out is the proper way to call a class from a
class.  I dont mean by extending the class, but actaully just getting the
functions...

For instance...

I'm trying to connect to a Database (database class) from my gen_XML class.
Do I include the database class in the gen_XML constructor?  Do I set a
gen_XML variable as a database object (i.e. $this->mydb)?

I hope my question makes some sense...

Your help is appreciated...

Mark Armendariz



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




RE: [PHP] class question 2

2002-03-27 Thread Martin Towell

once their instantiated, they're just like any other variable - that is: if
a "normal" variable, declared in the same place as the object, is accessable
in another function, then the object will be too.

HTH
Martin


-Original Message-
From: Caspar Kennerdale [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 28, 2002 1:17 PM
To: Php-General-List (E-mail)
Subject: [PHP] class question 2



Sorry Another question-

Do instances of classes remain in 'communication' with each other if
declared my different functions in a case switch statement.

At present I have an admin.php which is one long swtich statement.

Wihin each is a list iof functions which created the elements of the page

Each of these functions are defined in anither file and are instances of
classes.

If I create an instance of a DB class for exapmle- can I refer to it
thoughout the visit to the website-
ie does it maintaoin its values and variables even if different functions
freom the main index.php page are called

sorry if this is really confusing

any ideas much appreciated



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

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




RE: [PHP] class question 2

2002-03-27 Thread Rick Emery

Objects which are instantiated from classes on one page are not available on
the next page.  You have to use session functionality.

-Original Message-
From: Caspar Kennerdale [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 27, 2002 8:17 PM
To: Php-General-List (E-mail)
Subject: [PHP] class question 2



Sorry Another question-

Do instances of classes remain in 'communication' with each other if
declared my different functions in a case switch statement.

At present I have an admin.php which is one long swtich statement.

Wihin each is a list iof functions which created the elements of the page

Each of these functions are defined in anither file and are instances of
classes.

If I create an instance of a DB class for exapmle- can I refer to it
thoughout the visit to the website-
ie does it maintaoin its values and variables even if different functions
freom the main index.php page are called

sorry if this is really confusing

any ideas much appreciated



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

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




[PHP] class question 2

2002-03-27 Thread Caspar Kennerdale


Sorry Another question-

Do instances of classes remain in 'communication' with each other if
declared my different functions in a case switch statement.

At present I have an admin.php which is one long swtich statement.

Wihin each is a list iof functions which created the elements of the page

Each of these functions are defined in anither file and are instances of
classes.

If I create an instance of a DB class for exapmle- can I refer to it
thoughout the visit to the website-
ie does it maintaoin its values and variables even if different functions
freom the main index.php page are called

sorry if this is really confusing

any ideas much appreciated



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




Re: [PHP] Class question

2002-02-20 Thread Jeff Sheltren

Well, I guess many things are "accepted" now, but here's my two cents:

I wouldn't access global variables, instead you should pass everything you 
need as parameters.  Using global variables can come back to bite you 
occasionally because you may think you are changing a local variable at one 
point, but you actually change a global variable, and then who knows what 
will happen when you try to access the global variable later in your code 
expecting an int, for example, and it is suddenly a string...

As for using other user defined functions from elsewhere in your code, I 
think it depends on the context...  But think about what if you want to use 
this class elsewhere, then you will always need to copy over whatever file 
contains your other functions.  In that case it would obviously make more 
sense to contain whatever functions are needed inside of the class.

Hope that gives you some ideas.

Jeff

At 02:58 PM 2/20/2002 -0600, Chris Boget wrote:
>I'm still kind of new when it comes to dealing with classes.
>I'm curious, is it accepted practice for member functions of
>your class to:
>
>* access global variables
>* use non member, user defined functions
>
>Chris
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php



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




RE: [PHP] Class question

2002-02-20 Thread Hunter, Ray

The whole idea with object-oriented programming is polymorphism and
encapsulation.  You do not want your classes to access global variables but
access that information through objects and messaging between objects.  If
you are referring to the use of non-member as being outside of the class,
then again you want to use objects.  

As for practice, it is up to you.  For me, no...

Ray Hunter
Firmware Engineer

ENTERASYS NETWORKS


-Original Message-
From: Chris Boget [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, February 20, 2002 1:58 PM
To: PHP General
Subject: [PHP] Class question


I'm still kind of new when it comes to dealing with classes. I'm curious, is
it accepted practice for member functions of your class to:

* access global variables
* use non member, user defined functions

Chris


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



[PHP] Class question

2002-02-20 Thread Chris Boget

I'm still kind of new when it comes to dealing with classes.
I'm curious, is it accepted practice for member functions of
your class to:

* access global variables
* use non member, user defined functions

Chris


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




[PHP] Class Question

2001-06-21 Thread Unni

Hello,

This is the first time I write OOP in PHP. I wrote a small class for 
Mysql and from the index.php, I am calling the new function. I have a 
display before new class and I have a display after the new and only the 
display I am getting is the before class and after that there is no error.
Is there any thing I should know before using the class?

I have the class in a protected directory and index.php in the main 
directory.








and the class is

host = hostname;
   $this->db_name = dbname;
   $this->uid = uid;
   $this->pwd = pwd;
  
   $link = @mysql_db_connect($host, $uid, $pwd);
  
   }



   //*** run the query 
***   
   function run($query)
   {
   $this->number_of_columns = 0;
   $this->number_of_rows = 0;
   $this->return_code = 0;
   $this->error_info = "";
  
   $this->result = @mysql_db_query($db_name, $query, $link);
   if(!$result)
   {
   echo "Query didn't run";
   echo @mysql_error();
   $error_info = @mysql_error();
   }
   else
   {
   $number_of_columns = @mysql_num_fields($result);
   $number_of_rows = @mysql_num_rows($result);
   $error_info = "";
   }//end of bad return code
   return $return_code;
   }// end of run query function

   //* extract or fetch a row 
**
   function get_values()   
   {
   $this->row = @mysql_fetch_object($result);
   if($row)
   {
   extract($row);
   $return_code = 0;
   }
   else
   {
   $return_code = -1;
   }// end of if
   }//end of get_values function

}//end of class

?>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]