473,549 Members | 2,733 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using a Resource as a Class Property

I'm wondering if I'm doing this right, as far as using another class
object as a PHP class property.

class my_baseclass {
var $Database;
var $ErrorMessage;
var $TableName;
var $RecordSet;
function my_baseclass(){
$this->TableName = "";
$this->RecordSet = array();
$this->Database = new my_database();
$this->ErrorMessage = $this->Database->ErrorMessage ;
return true;
}
}

It seems to be working, but this kinds stuff skirts the edge of my PHP
grok, so I dunno.
Jul 21 '07 #1
61 2908
..oO(Sanders Kaufman)
>I'm wondering if I'm doing this right, as far as using another class
object as a PHP class property.

class my_baseclass {
var $Database;
var $ErrorMessage;
var $TableName;
var $RecordSet;
function my_baseclass(){
$this->TableName = "";
$this->RecordSet = array();
$this->Database = new my_database();
$this->ErrorMessage = $this->Database->ErrorMessage ;
return true;
}
}

It seems to be working, but this kinds stuff skirts the edge of my PHP
grok, so I dunno.
Using one object "inside" another is called an aggregation and a very
common and important concept in OOP.

But if you want to dive into that, I would strongly recommend to upgrade
to PHP 5 and make use of its OOP features.

Micha
Jul 21 '07 #2
Michael Fesser wrote:
.oO(Sanders Kaufman)
>I'm wondering if I'm doing this right, as far as using another class
object as a PHP class property.

class my_baseclass {
var $Database;
var $ErrorMessage;
var $TableName;
var $RecordSet;
function my_baseclass(){
$this->TableName = "";
$this->RecordSet = array();
$this->Database = new my_database();
$this->ErrorMessage = $this->Database->ErrorMessage ;
return true;
}
}

It seems to be working, but this kinds stuff skirts the edge of my PHP
grok, so I dunno.

Using one object "inside" another is called an aggregation and a very
common and important concept in OOP.
So I'm doing it right?! Cool. I know there are some cases where you're
supposed to serialize objects instead of... what am I doing, passing by
reference? Instantiating?

But if you want to dive into that, I would strongly recommend to upgrade
to PHP 5 and make use of its OOP features.
I soooooo want to do this in 5... but that won't be an option until like
October. Until then, it's gotta work on 4.
Jul 21 '07 #3
..oO(Sanders Kaufman)
>So I'm doing it right?! Cool.
It always depends on what you want to achieve. From just looking at the
posted snippet and without knowing what the my_baseclass is supposed to
do, it's hard to tell whether you're doing it right or not, since the
code is not doing anything useful, except for initializing some member
variables.
>I know there are some cases where you're
supposed to serialize objects instead of... what am I doing, passing by
reference? Instantiating?
Aggregating. ;) You create an instance of a class, which is used inside
another object. That's it (in this case).

Serializing can be used if you want to store an object to a file or a
database.

Micha
Jul 21 '07 #4
Sanders Kaufman wrote:
function CreateTable($sT ableName, $sTableDef){
//Returns true, or false with an ErrorMessage.
//Prefixes table name and appends ISAM engine type.
//Auto-creates id field, but user should still provide a unique
field
$bRetVal = true;
$this->RecordSQL = "CREATE TABLE {$this->TablePrefix}_$ sTableName
(id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id),
$sTableDef) ENGINE=MyISAM";
if(!$this->RunSQL($this->RecordSQL)){
$bRetVal = false;
$this->ErrorMessage=m ysql_error();
} else {
$this->ErrorMessage=" OK";
}
return $bRetVal;
}

This is actually one of the parts of my architecture I'm most proud of.
By specifying a table prefix in the class, it allows multiple web
applications to all use the same database, without any problem with same
names.

For example, suppose you use this framework to build a discussion forum
program. A client then uses it to build to web sites that use the same
database server (e.g. kaiser.kaufman. net and caesar.kaufman. net, both
using mysql.kaufman.n et).

If the discussion forum uses a "users" table, then the developer can
isolate one from the other by specifying a unite table prefix.
Jul 21 '07 #5
Sanders Kaufman wrote:
class bvckvs_database
You seem to have re-invented PDO/MDB2.

http://en.wikipedia.org/wiki/Reinventing_the_wheel

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 31 days, 5:12.]

Parsing an HTML Table with PEAR's XML_HTTPSax3
http://tobyinkster.co.uk/blog/2007/0...table-parsing/
Jul 22 '07 #6
Sanders Kaufman wrote:
If the discussion forum uses a "users" table, then the developer can
isolate one from the other by specifying a unite table prefix.
Yep -- it's a fairly common construct. It's arguably better to use
schemas, but not all RDBMSs have very good support for that.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 31 days, 5:16.]

Parsing an HTML Table with PEAR's XML_HTTPSax3
http://tobyinkster.co.uk/blog/2007/0...table-parsing/
Jul 22 '07 #7
Toby A Inkster wrote:
Sanders Kaufman wrote:
>class bvckvs_database

You seem to have re-invented PDO/MDB2.

http://en.wikipedia.org/wiki/Reinventing_the_wheel
They say that everything that will ever be written, has already been
written.
Jul 22 '07 #8
Toby A Inkster wrote:
Sanders Kaufman wrote:
>If the discussion forum uses a "users" table, then the developer can
isolate one from the other by specifying a unite table prefix.

Yep -- it's a fairly common construct. It's arguably better to use
schemas, but not all RDBMSs have very good support for that.
Really? Common, eh? I guess I should shelve my ideas for velcro and
the frisbee, as well.

But yeah - DBMS portability was a core design concept.
Jul 22 '07 #9
Michael Fesser wrote:
.oO(Sanders Kaufman)
class my_childclass extends my_baseclass {
function my_childclass() {
// first call parent constructor or we won't have a database ...
parent::my_base class();
// then do some other stuff
...

OK - that seems to be where I went wrong. I thought the base class's
constructor was automatically called when the extended class's was.

So, bottom line, what you're saying here is that when you extend a base
class like this, you still have to manually call the base class's
constructor? Zat right?
Jul 22 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
7661
by: David Muoio | last post by:
I am trying to validate an XML file against an XSD that is stored in the assembly as an embedded resource. I can get it to work as long as the XSD does not include other XSDs. After a fair amount of searching, I have found 3 possible solutions but none have worked for me. They are: 1. Use the Includes property of XmlSchema to add included...
8
13097
by: Dennis C. Drumm | last post by:
I have ordered the book .NET Framework Solutions, In Search of the Lost Win32 API by John Paul Meuller which I think will help answer some of my questions I have regarding making custom MessageBoxes, but that isn't going to be here for a few days. So, I thought I would ask you guys how to put one of hte standard MessageBox icons, such as...
3
6872
by: Patrick Fogarty | last post by:
I am programming what is to be a web service client that will use an HTTP-POST to request and retrieve data. The remote server (written in java for what it's worth) requires basic authentication as per RFC 2617 (http://www.faqs.org/rfcs/rfc2617.html). My attempts to authenticate are failing. The server requires the header to be present with...
8
10403
by: Marc Gravell | last post by:
I want to write a method that will accept a stream as a parameter, and which will write xml to the stream (based in reality on database results) using the XmlTextWriter class. However, this insists on closing my stream, and I can't convince it not to. A much-simplified example is below; basically, as soon as the writer is disposed (marked...
6
15930
by: David Veeneman | last post by:
How do I configure a .NET 2.0 SoundPlayer object to play a WAV file embedded as a resource? I have tried the example in the MSDN documentation, and I am getting nowhere. Is there a simple example of how to do this, or can someone provide an example? Thanks. David Veeneman Foresight Systems
2
1312
by: Rich | last post by:
I have seen DLL projects use .res files so that when you look at the properties of the DLL file from Windows Explorer you can see things like file version, description, copyright, etc. My question is how do you do this? (specifically, using MS C++ 2005 Express). I have found hints in MSDN that indicate that you must first create a ".rc"...
7
3454
by: Rich | last post by:
I am resurrecting this question (since it got bumped down by more recent posts). This is probably very simple - I need to add a version resource to a DLL project in MSVC++ 2005 Express in order to have version info, copyright, etc. when checking the DLL file properties from Windows Explorer. Any guidance is appreciated.
0
900
by: Galen Somerville | last post by:
I'm not using Cultures so I just want to pull strings out of a Resource dll. In References there is a reference to the CDS80Eng.dll Partial code in a module --------------- Public Function GetResource() As Boolean Public clsRes As CDS80Eng.CDS80Eng Public Function GetResource() As Boolean
2
8726
by: Nathan Sokalski | last post by:
I am attempting to create icons for controls I have created using VB.NET by using the System.Drawing.ToolboxBitmap attribute. I have managed to do this in C# by specifying the path to the *.ico file, but I have been unable to get any of the overloads to work in VB.NET. I would like to store the *.ico files in a *.resx file so that users do not...
12
77948
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I am a newbie to Struts and JSP...I have been working on the code below for 5 hours now..I googled a lot but couldn't get much help so finally I am here.. Hoping of getting my problem solved. Please give me some idea where I am going wrong ?? I just want to retrieve data from my emp_mstr table and display it using my JSP file... The table...
0
7451
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7720
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7960
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7812
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5372
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5089
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.