|
Posted by Erwin Moller on 02/01/06 12:22
Jerry Stuckle wrote:
> Erwin Moller wrote:
<snip>
>>
>> Bad programming?
>> Says who?
>> And why?
>>
>> Only use Objects if they add something to your code or structure somehow.
>> (Like PEAR:DB)
>> I really don't see the problem with making $connection global...
>>
>> Regards,
>> Erwin Moller
>
>
> Yes, bad programming. It binds all of your code to the variable
> $connection, among other things.
No, I use it only in functions that need the connection.
If a script needs the connection it gets the connection by means of a
include at top of the script.
If you need to change that you have a
> huge amount of code to change.
Why should somebody want to change the connection-object?
It is needed for database-access.
If I need to change that I am really making a new program.
It also makes the code less portable.
> Also, if $connection gets changed someplace, you'll have a hell of a
> time trying to debug it.
Sorry, thanks for replying, and I do not want to pick a fight with you, but
this doesn't make sense.
I can say the same for your object-oriented approach, look:
- If you use an (singleton) Object to deliver the connection, you bind all
your code to that object.
and
- If the connection in the object somehow get changed, all code breaks.
and
Does that make sense to you?
Of course not!
You know where you need a databaseconnection and get it delivered somehow,
singleton Object or global connection.
Both are lines of code, and both deliver the same in the end: a working
connection.
>
> Globals in general are bad ideas.
Not if you need an outside variable inside a function.
It is perfectly legal.
I could also deliver the connection by refrence every call to every function
that needs the connection.
No big diff.
Please remember that we are NOT talking about globals as in ASP
(Application), but just globals for the duration of the script.
>
> Citrus's design is much better. There is a little overhead - but not
> all that much.
Yes, Citrus claimed the same.
Also without any argumentation that made any sense.
If you are so sure of the superiority of the Object approach, why can you
not tell us why?
>
> And I find objects almost always improve the structure of my code. It
> also makes it more flexible and configurable. For instance - I can
> easily change databases simply by changing the database object. No
> changes in my code are necessary.
No changes in your code needed?
Of course you need to change something in your code, the Object that makes
the connection is changed by you.
Now compare this to an include that delivers the connection: I also have 1
place to change the connection, and it is included everywhere.
Then everywhere where 'global $connection;' is used, the connection is
up-to-date.
Don't try to sell nonsense to me.
I developed years and years in Java, and do not fall for laymans arguments.
Please give me a serious response that dives into the issue instead of
claims that are clearly not true.
Another thing: In PHP Objects are only halfhearted and last only for the
duration of the script. They are not persistent. (Unless of course you
serialize and deserialize them from script to script, but that is not
exactly persistent.)
Object in PHP are nothing more than a bundling of some functions together,
and their own namespace. Really that is all there is to it.
Don't try to make more of it than that.
Heck - I can even use flat files when
> necessary!
>
So can I, but what has that to do with this issue?
Are you suggesting that Objects are the next step in evolution of the
$connection in scripts? Haha.
Regards,
Erwin Moller
[Back to original message]
|