473,406 Members | 2,745 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,406 software developers and data experts.

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
61 2893
Sanders Kaufman wrote:
Jerry Stuckle wrote:
>You can't change the base class method - by definition, it's part of
the interface. But the variable is part of the implementation. In a
proper design you can change the variable (and, of course, the BODY of
functions which reference it) without changing the interface - and the
child classes.


Speaking of named methods and overrides...
I just now realized that I had a TableName property in both my baseclass
and my extended class... accidentally overriding, right?

But... can I still have it in both places, calling the baseclass
property with one of those :: operators?

Or does the overriding kill that altogether?
No, overriding doesn't kill this. However, generally you would want to
call the derived class's function, and that one would call the base
class's function.

If the functions have the same name, the child class's function should
be an extension of the base class's function. If the child class
function is not, it should have a different name.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 24 '07 #51
Sanders Kaufman wrote:
Jerry Stuckle wrote:
>Sanders Kaufman wrote:
>>Also, the idea of doing this:
"$x = new MyObject($y, $z)"
instead of this:
"$x = new MyObject()"
just *feels* wrong to me.

I'm not sure why - but it's probably legacy cringing from some other
platform and package in my past.

Not at all. The whole purpose of the constructor is to initialize the
object. It is probably more common to pass parameters to the object's
constructor than not.

For instance, the constructor for the mysqli class:

mysqli mysqli_connect ( [string host [, string username [, string
passwd [, string dbname [, int port [, string socket]]]]]] )

If you pass a host, it will try to connect to the host. If you pass a
username, it will connect using that username. If password is
specified, it will also use that password, etc.

If no parameters are specified, then no connection is attempted.

Yeah - I'm totally cool with the fact that some folks use parms in the
construction, and on a thinky level, I can certainly see where it would
be handy. But it really feels wrong.

I have the same issue with using voids... although I use 'em, it just
feels like the same kind of wrong.
Actually, it's not that much different than defining a variable and
providing it a value, i.e.

$i = 3;

Of course there isn't any way to define a simple variable in an untyped
language like PHP, but it's still considered good form in typed languages.

About the closes you could come in PHP is defining and initializing an
array, i.e.

$i = array('zero', 'one', 'two');

Not always done, but you get the idea.
>
>>This looks like something I'm going to have to HEAVILY consider in
the next iteration of the code - abstract classes, interfaces and
function overrides.

Yep.

I'd also recommend you pick up a decent book on OO in general. It
will explain things a lot better than we can here in the newsgroup.

I'm not very good about learning from tutorial books. I get all the way
through, don't miss a thing, do all of the exercises... and then have no
idea what I learned.

If I'm gonna learn this stuff, it's gonna be because someone taught it
to me here and in the OOP groups. I'll probably also draw up a nice
poster to remind me about Inheritance, Polymorphism, Abstraction and
Encapsulation.
You still need to look at the books. Sure, you'll have questions. But
a good book will also answer a lot of questions you might have.

And as I said - it's impossible to get into the amount of detail here in
a newsgroup that you can get from a book.

I teach an OO course. It's five days of intensive learning. OO books
are 200-300 pages or more. There's no way we can handle that type of
detail in a newsgroup.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 24 '07 #52
Jerry Stuckle wrote:
Sanders Kaufman wrote:
>I just now realized that I had a TableName property in both my
baseclass and my extended class... accidentally overriding, right?

But... can I still have it in both places, calling the baseclass
property with one of those :: operators?

Or does the overriding kill that altogether?

No, overriding doesn't kill this. However, generally you would want to
call the derived class's function, and that one would call the base
class's function.

If the functions have the same name, the child class's function should
be an extension of the base class's function. If the child class
function is not, it should have a different name.
So when I override a function, it actually calls the baseclass function
AND THEN the derived function? Did I understand that right?
Jul 24 '07 #53
Jerry Stuckle wrote:
Sanders Kaufman wrote:
>Yeah - I'm totally cool with the fact that some folks use parms in the
construction, and on a thinky level, I can certainly see where it
would be handy. But it really feels wrong.

I have the same issue with using voids... although I use 'em, it just
feels like the same kind of wrong.

Actually, it's not that much different than defining a variable and
providing it a value, i.e.

$i = 3;
Good point.

I teach an OO course. It's five days of intensive learning. OO books
are 200-300 pages or more. There's no way we can handle that type of
detail in a newsgroup.
Classes rock.
Jul 24 '07 #54
Sanders Kaufman wrote:
Jerry Stuckle wrote:
>Sanders Kaufman wrote:
>>I just now realized that I had a TableName property in both my
baseclass and my extended class... accidentally overriding, right?

But... can I still have it in both places, calling the baseclass
property with one of those :: operators?

Or does the overriding kill that altogether?

No, overriding doesn't kill this. However, generally you would want
to call the derived class's function, and that one would call the base
class's function.

If the functions have the same name, the child class's function should
be an extension of the base class's function. If the child class
function is not, it should have a different name.

So when I override a function, it actually calls the baseclass function
AND THEN the derived function? Did I understand that right?
No, it doesn't. It only calls the derived class function. But the
derived class function should call the base class function.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 24 '07 #55
Sanders Kaufman wrote:
Jerry Stuckle wrote:
>Sanders Kaufman wrote:
>>Yeah - I'm totally cool with the fact that some folks use parms in
the construction, and on a thinky level, I can certainly see where it
would be handy. But it really feels wrong.

I have the same issue with using voids... although I use 'em, it just
feels like the same kind of wrong.

Actually, it's not that much different than defining a variable and
providing it a value, i.e.

$i = 3;

Good point.

>I teach an OO course. It's five days of intensive learning. OO books
are 200-300 pages or more. There's no way we can handle that type of
detail in a newsgroup.

Classes rock.
Yes, my customers (all corporate) think so. But they're not cheap,
either :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 24 '07 #56
Jerry Stuckle wrote:
Sanders Kaufman wrote:
>So when I override a function, it actually calls the baseclass
function AND THEN the derived function? Did I understand that right?

No, it doesn't. It only calls the derived class function. But the
derived class function should call the base class function.
Oh, OK. I misunderstood "should".
You're saying that if I override a function, I should be calling the
overridden function from within the override at some point.
This is an OOP design principle, but not necessarily enforced in the
compiler/IDE thingies.
It's that way because, there's not much point in writing a function that
just gets voided in the actual implementation and because it allows you
to put some shared or common functionality deeper down (higher up?) into
the foundation of the architecture.

Zat right?
Jul 24 '07 #57
Jerry Stuckle wrote:
Sanders Kaufman wrote:
>Jerry Stuckle wrote:
>>I teach an OO course. It's five days of intensive learning. OO
books are 200-300 pages or more. There's no way we can handle that
type of detail in a newsgroup.

Classes rock.

Yes, my customers (all corporate) think so. But they're not cheap,
either :-)
What a great racket.
I got a friend does that with OSHA training.
She makes WAAAAY too much money teaching cubicle rats how to use
automagic defibrilators.
Jul 24 '07 #58
Sanders Kaufman wrote:
My baseclass is not designed to be instantiated, and it kinda irked me
that it could be. I even added a bit of PHPDoc to warn the developer
not to try. But that's a lousy way to code!
In PHP5 you can mark this as an abstract class. The interpreter prevents
anyone from instantiating an abstract class.

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

Parsing an HTML Table with PEAR's XML_HTTPSax3
http://tobyinkster.co.uk/blog/2007/0...table-parsing/
Jul 24 '07 #59
Sanders Kaufman wrote:
Jerry Stuckle wrote:
>Sanders Kaufman wrote:
>>So when I override a function, it actually calls the baseclass
function AND THEN the derived function? Did I understand that right?

No, it doesn't. It only calls the derived class function. But the
derived class function should call the base class function.

Oh, OK. I misunderstood "should".
You're saying that if I override a function, I should be calling the
overridden function from within the override at some point.
This is an OOP design principle, but not necessarily enforced in the
compiler/IDE thingies.
It's that way because, there's not much point in writing a function that
just gets voided in the actual implementation and because it allows you
to put some shared or common functionality deeper down (higher up?) into
the foundation of the architecture.

Zat right?
That is true. The problem is - if you don't call the base class
function, work the base class needs to do for other things may not be
performed. For instance, a variable in the base class may not be set,
and that variable may be used in a subsequent call to a base class function.

No, compilers don't enforce it. But it's a good idea.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 24 '07 #60
Sanders Kaufman wrote:
Jerry Stuckle wrote:
>Sanders Kaufman wrote:
>>Jerry Stuckle wrote:
>>>I teach an OO course. It's five days of intensive learning. OO
books are 200-300 pages or more. There's no way we can handle that
type of detail in a newsgroup.

Classes rock.

Yes, my customers (all corporate) think so. But they're not cheap,
either :-)

What a great racket.
I got a friend does that with OSHA training.
She makes WAAAAY too much money teaching cubicle rats how to use
automagic defibrilators.
You'd be surprised. It's not all that great money, and it's a lot of
hard work. You wouldn't believe what I have to pay for an instructor
(no, I don't do all the classes myself).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 24 '07 #61
Jerry Stuckle wrote:
Sanders Kaufman wrote:
>I got a friend does that with OSHA training.
She makes WAAAAY too much money teaching cubicle rats how to use
automagic defibrilators.

You'd be surprised. It's not all that great money, and it's a lot of
hard work. You wouldn't believe what I have to pay for an instructor
(no, I don't do all the classes myself).
Yeah - it's hard work. I think the hardest part is that it's as much
about being sociable as it is about being an expert in the subject.

Me - I couldn't sell a pardon to a prisoner.
Jul 24 '07 #62

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

Similar topics

2
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...
8
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...
3
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...
8
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...
6
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...
2
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...
7
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...
0
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...
2
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...
12
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
0
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...

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.