473,395 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Some class help (php5)

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
6 1229
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
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
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
..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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: neur0maniak | last post by:
Hi, I've been eager to try out PHP5, so I've dumped it on my little dev machine. It's running WinXP with IIS5. I've put the php-cgi.exe in the "mappings" page as I'm used to doing with PHP4....
4
by: R | last post by:
Hello. I've got a strange situation. I've got class Handlers it's only: class Handlers { var $DB; var $XML; }
7
by: Markus Elfring | last post by:
Hello, 1. Will the functionality of the chapter "CXII. String Functions" (http://de.php.net/manual/en/ref.strings.php) be wrapped into PEAR classes and packages? 2. What does happen with the...
4
by: Doug | last post by:
Say I have a class with a constant in it. I also have a variable in that class that I would like to set to that constant as the initialization value. Why doesn't the following work? class...
2
by: Peter Fox | last post by:
<?php /* Making up class properties on the fly! -------------------------------------- PHP version 4.3.5 An instance of a class can have properties added on the fly. This behaviour...
0
by: Samuel Zallocco | last post by:
Hi all, I've a problem with PHP5 + PEAR::SOAP. I Have the following 2 script that implements a simple web service: The Server Code running on WinXP + PHP5 + Apache 2.x:...
15
by: tatsudoshi | last post by:
Hello, I have this class http://pastebin.com/807571, where I set some variables on __construct. Originaly I set the $total_? variables when the function showLayout() was called. I know pastebin...
19
by: McKirahan | last post by:
I am working in two environments neither configuration of which I can change; one's my Web host the other a client. My Web host requires the use of the ".php5" extension to use PHP v5.1.4; where...
21
by: Daz | last post by:
Hi everyone. I am trying to create an extension of the mysqli class within PHP, and I am finding it quite difficult. I am fairly new to PHP classes, and decided to give them a go. Here's what I...
4
by: dougans | last post by:
Hey there, Hope someone can help me, completely stuck with immigrating from php4 to OOP based php5. == index.php -- include(database.inc.php);
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.