By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,653 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

Some class help (php5)

P: n/a
Hello

I have a "base class" for my application, that holds a protected
variable called $db. $db is an ADODB object for the database.

When I make a class that extends the base class, $this->db does not work
(Call to a member function x on a non-object). How would I use the base
class's $db variable in it?
Aug 24 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Sorry, I forgot to mention that the class that extends the base class is
created in the base class.

Sweetiecakes wrote:
Hello

I have a "base class" for my application, that holds a protected
variable called $db. $db is an ADODB object for the database.

When I make a class that extends the base class, $this->db does not work
(Call to a member function x on a non-object). How would I use the base
class's $db variable in it?
Aug 24 '08 #2

P: n/a
Sweetiecakes <x@x.comwrote in comp.lang.php:
Hello

I have a "base class" for my application, that holds a protected
variable called $db. $db is an ADODB object for the database.

When I make a class that extends the base class, $this->db does not work
(Call to a member function x on a non-object). How would I use the base
class's $db variable in it?
Look up the scope resolution operator (::) to refer to properties/methods
of objects. Probably you want:

baseClassObj::db

http://us3.php.net/manual/en/languag...ekudotayim.php


Aug 24 '08 #3

P: n/a
Hi

If I try to use "parent::$db", the following error shows up:

Access to undeclared static property

If I try to use "parent::db", the following error showsup:

Undefined class constant 'db'

Five By Five wrote:
Sweetiecakes <x@x.comwrote in comp.lang.php:
>Hello

I have a "base class" for my application, that holds a protected
variable called $db. $db is an ADODB object for the database.

When I make a class that extends the base class, $this->db does not work
(Call to a member function x on a non-object). How would I use the base
class's $db variable in it?

Look up the scope resolution operator (::) to refer to properties/methods
of objects. Probably you want:

baseClassObj::db

http://us3.php.net/manual/en/languag...ekudotayim.php

Aug 24 '08 #4

P: n/a
..oO(Sweetiecakes)
>I have a "base class" for my application, that holds a protected
variable called $db. $db is an ADODB object for the database.

When I make a class that extends the base class, $this->db does not work
(Call to a member function x on a non-object). How would I use the base
class's $db variable in it?
You do it with $this->db. Can you post some code?

Micha
Aug 24 '08 #5

P: n/a
Sweetiecakes <x@x.comwrote in comp.lang.php:
Hi

If I try to use "parent::$db", the following error shows up:

Access to undeclared static property

If I try to use "parent::db", the following error showsup:

Undefined class constant 'db'

Try parent->db or possibly $this->db. Without code posted, it's tought to
tell.

Top-posting is frowned on, by the way.

>
Five By Five wrote:
>Sweetiecakes <x@x.comwrote in comp.lang.php:
>>Hello

I have a "base class" for my application, that holds a protected
variable called $db. $db is an ADODB object for the database.

When I make a class that extends the base class, $this->db does not
work (Call to a member function x on a non-object). How would I use
the base class's $db variable in it?

Look up the scope resolution operator (::) to refer to
properties/methods of objects. Probably you want:

baseClassObj::db

http://us3.php.net/manual/en/languag...ekudotayim.php



Aug 24 '08 #6

P: n/a
On Aug 24, 4:13*pm, Sweetiecakes <x...@x.comwrote:
Sorry, I forgot to mention that the class that extends the base class is
created in the base class.

Sweetiecakes wrote:
Hello
I have a "base class" for my application, that holds a protected
variable called $db. $db is an ADODB object for the database.
When I make a class that extends the base class, $this->db does not work
(Call to a member function x on a non-object). How would I use the base
class's $db variable in it?

You're trying to define a class within a class? As far as I'm aware
that's not possible in PHP.

class foo
{
protected $db

class bar
{
if ($this -db)
{
...
}
}
}

is not possible in PHP as far as I'm aware. The following should be
valid (not tested).

class Foo
{
protected $db = 'test';
}

class Bar extends Foo
{
function getDb ()
{
return ($this -db);
}
}

$thisObj = new Bar;
echo ($thisObj -getDb ());
Aug 24 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.