473,506 Members | 14,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Which is better OOP, and why?

Dan
I have seen differing ways to pass values to a class:

$db=new mysqlclass('localhost','user','passwd','database') ;
.....
OR

$db=new mysqlclass()
$db->host='localhost';
$db->user='user';
$db->passwd='passwd';
$db->database='database';
.....

To me, the second looks like more typing. But if the argument list to the
class changes, the latter would not be effected. I am trying to drag my
brain (kicking and scratching) into OOP. Any thoughts on this would be
appreciated.

Thanks

Dan
Jul 17 '05 #1
14 2117
Dan wrote:
I have seen differing ways to pass values to a class:

$db=new mysqlclass('localhost','user','passwd','database') ;
....
OR

$db=new mysqlclass()
$db->host='localhost';
$db->user='user';
$db->passwd='passwd';
$db->database='database';


Usually, I use both ways. For instance, in the class constructor, I
allow parameters to be sent as arguements (usually in an array), but
leave them optional.

I set up mutator methods like:
function setHost($x){ $this->host = $x; return TRUE; }
function setUser($x){ $this->user = $x; return TRUE; }
function setPass($x){ $this->passwd = $x; return TRUE; }
function setDB($x){ $this->db = $x; return TRUE; }

As well as accessor methods like:
function getHost($x){ return $this->host; }
function getUser($x){ return $this->user; }
function getPass($x){ return $this->passwd; }
function getDB($x){ return $this->db; }

Then I have the ability to set up utility methods:
function resetConnection(){ return $this->mysqlclass(); }

That way, if you want to change sql servers, you don't need to create
another object, just use something like:

$db->setHost='localhost';
$db->setUser='user';
$db->setPass='passwd';
$db->setDB='database';
$db->resetConnection();

You'd also be able to get the connection information via the accessor
methods to check what conection you have open.

This method also gives you the ability to change variable names in the
class without effecting the API of it - making it easier to maintain and
sometimes more portable.

I guess it all depends if you want to go the true OOP route like C++
where there are private and public methods, or like PHP4, where
everything is public. I usually try to stick with the strict C++
methodology in order to force myself to create better code. (My thinking
here is that if I am forced to create all these methods, I may as well
spend the extra few minutes checking all input and writing error codes
and such that re easier to debug down the road.)

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.
Official Google SERPs SEO Competition: http://www.koivi.com/serps.php
Jul 17 '05 #2
Dan:
I have seen differing ways to pass values to a class:

$db=new mysqlclass('localhost','user','passwd','database') ;
....
OR

$db=new mysqlclass()
$db->host='localhost';
$db->user='user';
$db->passwd='passwd';
$db->database='database';
....

To me, the second looks like more typing. But if the argument list to the
class changes, the latter would not be effected. I am trying to drag my
brain (kicking and scratching) into OOP. Any thoughts on this would be
appreciated.


I'd like to add that the former makes it easier to avoid errors from
forgetting to pass some necessary value, but I guess you can implement that
kind of checks on your own.

One thing I greatly miss in PHP is keyword arguments. This simple feature is
very useful when generating HTML. For example you can have a syntax like:

createTable(:border 0, :cellpadding 1 , :cellspacing 1);

But alas, this is not possible, and I haven't seen it suggested for the 5.0
release.

One possible option is to use a combination. Now I guess we can safely
assume that the four parameters in your example are necessary. To add
something similar to keyword arguments you can pass an associative array in
addition containing these.

Say we have the createTable function again, and let's assume that this
function always expects a set of data to generate a table from. So we can
have this signature:

function createTable($data, $options);

Where $options is expected to be an associative array of optional arguments
which is obviously very simple to extend. It's not very elegant, but it
works.

IMO the worst solution is to use optional arguments. I've been in the same
sort of problem myself where I had a list of optional arguments, and then I
needed to change the value of the 4th. optional argument, yet let the 3
first remain unchanged. In this case I had to look up and pass the default
value of the 3 first parameters.

I've also seen people use something like setOption('optionName', 'value');
but in most cases these feels like overkill. Finally you can of course use
getters/setters for all the relevant options, again this feels like
overkill most of the time.

André Næss
Jul 17 '05 #3
With total disregard for any kind of safety measures André Næss
<an*********************@ifi.uio.no> leapt forth and uttered:
One possible option is to use a combination. Now I guess we can
safely assume that the four parameters in your example are
necessary. To add something similar to keyword arguments you can
pass an associative array in addition containing these.


Or you could pass the arguments as a string and roll your own
argument parser.

function argParse($str) {
$arg_pairs = explode(',', $str);
$arguments = array();
foreach($arg_pairs as $pair) {
list($key, $val) = explode(' ', $pair);
$arguments[trim($key)] = trim($val);
}
return $arguments;
}

Passing the hash array leads to less processing, but a lot more
typing. I suppose it depends on your preference.

--
Phil Roberts | Nobody In Particular | http://www.flatnet.net/
Jul 17 '05 #4

On 10-Feb-2004, "Dan" <ji****@aol.nospam.please.com> wrote:
I have seen differing ways to pass values to a class:

$db=new mysqlclass('localhost','user','passwd','database') ;
....
OR

$db=new mysqlclass()
$db->host='localhost';
$db->user='user';
$db->passwd='passwd';
$db->database='database';
....

To me, the second looks like more typing. But if the argument list to the
class changes, the latter would not be effected. I am trying to drag my
brain (kicking and scratching) into OOP. Any thoughts on this would be
appreciated.


Strict OOP would rule out the second approach because it violates
encapsulation. You would have to create methods for setting/retrieving the
values to/from the variables.

$db->setHost('localhost');

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #5

"Justin Koivisto" <sp**@koivi.com> wrote in message news:wf****************@news7.onvoy.net...
Dan wrote:
I have seen differing ways to pass values to a class:

$db=new mysqlclass('localhost','user','passwd','database') ;
....
OR

$db=new mysqlclass()
....

Usually, I use both ways. For instance, in the class constructor, I
allow parameters to be sent as arguements (usually in an array), but
leave them optional.


Yes I believe that this is best way to go. In OOP you want an object to be ready to go at creation time. If the programmer has to
set a ton of variables manually, then it not only becomes a lot of typing, but the user of the class has to know too much. My rule
of thumb is to have a constructor function that takes all the variable necessary to create the object. Optional variables may or may
not be included in the constructor, but will have the ability to be set by accessor functions. Incidentally I don't typically allow
accessor functions to set the core variables necessary to create the object.

I think it's a bad habit to try to change an object's core once it's been instantiated. If the object has to morph that
dramatically, then it probably (though not always) really represents a new object.

-CF
Jul 17 '05 #6
ChronoFish wrote:
"Justin Koivisto" <sp**@koivi.com> wrote in message news:wf****************@news7.onvoy.net...
Dan wrote:
I have seen differing ways to pass values to a class:

$db=new mysqlclass('localhost','user','passwd','database') ;
....
OR

$db=new mysqlclass()

Usually, I use both ways. For instance, in the class constructor, I
allow parameters to be sent as arguements (usually in an array), but
leave them optional.


Yes I believe that this is best way to go. In OOP you want an object to be ready to go at creation time. If the programmer has to
set a ton of variables manually, then it not only becomes a lot of typing, but the user of the class has to know too much. My rule
of thumb is to have a constructor function that takes all the variable necessary to create the object. Optional variables may or may
not be included in the constructor, but will have the ability to be set by accessor functions. Incidentally I don't typically allow
accessor functions to set the core variables necessary to create the object.

I think it's a bad habit to try to change an object's core once it's been instantiated. If the object has to morph that
dramatically, then it probably (though not always) really represents a new object.


That is usually true, so I don't use that type of stuff often (like the
example of a method that called the constructor). However, I did create
a class for online listings that did something like that. Once the
object was created, you could use a load($id) method, then use mutators
to change stuff followed by a save(). Since it was being used in a loop
quite often, I created a clear() method that basically started over with
an empty object. May not be the best solution, but it did cut down on
processing (memory useage was almost identical) by about 2 seconds when
dealing with several thousand listings.

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.
Official Google SERPs SEO Competition: http://www.koivi.com/serps.php
Jul 17 '05 #7
Justin Koivisto wrote:
Dan wrote:
I have seen differing ways to pass values to a class:

$db=new mysqlclass('localhost','user','passwd','database') ;
....
OR

$db=new mysqlclass()
$db->host='localhost';
$db->user='user';
$db->passwd='passwd';
$db->database='database';

Usually, I use both ways. For instance, in the class constructor, I
allow parameters to be sent as arguements (usually in an array), but
leave them optional.


So the object created without all necessary parameters is not usable.
Bad Thing(tm).
I set up mutator methods like:
function setHost($x){ $this->host = $x; return TRUE; }
function setUser($x){ $this->user = $x; return TRUE; }
function setPass($x){ $this->passwd = $x; return TRUE; }
function setDB($x){ $this->db = $x; return TRUE; } As well as accessor methods like:
function getHost($x){ return $this->host; }
function getUser($x){ return $this->user; }
function getPass($x){ return $this->passwd; }
function getDB($x){ return $this->db; }
If your object expose all of it's internal state, it's bad luck. What
happens if you instanciate the object with all parameters and then
change the 'User' field only ?
Then I have the ability to set up utility methods:
function resetConnection(){ return $this->mysqlclass(); }
You don't need to expose all the object's internal state to write this
kind of method :
That way, if you want to change sql servers, you don't need to create
another object, just use something like:

$db->setHost='localhost';
$db->setUser='user';
$db->setPass='passwd';
$db->setDB='database';
$db->resetConnection();
lol, and yuck :(

firstly, i'm afraid this code is awfully broken. Should be :
$db->setHost('localhost');

Then, what happens with this :
$db->setPass('');
$db->resetConnection();

For this to be not too awful, you'd need :
$db->resetConnection('host', 'user', 'pass', 'db');

But then - in this particular case - it's just like you've created a new
object :
$db = new Db('host', 'user', 'pass', 'db');

You'd also be able to get the connection information via the accessor
methods to check what conection you have open.
And if you changed one of the connection information, and then did not
'reset' connection ? out of sync info is worse than no info.
This method also gives you the ability to change variable names in the
class without effecting the API of it - making it easier to maintain and
sometimes more portable.
Yes, what a great deal... internally rename '$this->user' to
'$this->m_str_user_name' without affecting the 'API' (er...).
I guess it all depends if you want to go the true OOP route like C++
where there are private and public methods, or like PHP4, where
everything is public.
What is 'public' is what you use outside of the class. What is 'private'
is what you dont use outside of the class. No need to enforce this with
builtin keywords and compiler checks.
I usually try to stick with the strict C++
methodology in order to force myself to create better code. (My thinking
here is that if I am forced to create all these methods, I may as well
spend the extra few minutes checking all input and writing error codes
and such that re easier to debug down the road.)


Nothing forces you to write any getter/setter unless the client code
really needs it. Should read the pragmatic programmer's advices :
http://www.pragmaticprogrammer.com/p...s/1998_05.html

Now i'm not telling that getter/setter are a Bad Thing by themselves,
just that you should make a distinction between what is the class
'Knowledge Responsability' (ie : what client code is entitled to ask the
class) and what is in fact internal state. If you happen to query the
object about it's internal state just in order to decide what you're
going to tell him to do next, then you've broken encapsulation, and
you'd better fix your code right now. One important rule here is that
you never should bother about the internal state of an object before
sending him a message.

My 2 cents,
Bruno

Jul 17 '05 #8
Dan wrote:
I have seen differing ways to pass values to a class:

$db=new mysqlclass('localhost','user','passwd','database') ;
....
OR

$db=new mysqlclass()
$db->host='localhost';
$db->user='user';
$db->passwd='passwd';
$db->database='database';
....

To me, the second looks like more typing. But if the argument list to the
class changes, the latter would not be effected.


And what happens with this code ?

$db = new Db();
// no user, no pwd, no host, no nothing
$db->doSomething();
// wham ! doSomething() supposed the object was fully initialized.
// Too bad
If the arg list of the ctor have to change, change it and change client
code. What's worse ? a clean fix, or a Q&D workaround ?

My 2 cents
Bruno

Jul 17 '05 #9
Bruno Desthuilliers wrote:
Justin Koivisto wrote:
Dan wrote:
I have seen differing ways to pass values to a class:

$db=new mysqlclass('localhost','user','passwd','database') ;
....
OR

$db=new mysqlclass()
$db->host='localhost';
$db->user='user';
$db->passwd='passwd';
$db->database='database';
Usually, I use both ways. For instance, in the class constructor, I
allow parameters to be sent as arguements (usually in an array), but
leave them optional.


So the object created without all necessary parameters is not usable.
Bad Thing(tm).


I should have made that more clear. Objects that *need* stuff to work
would have them required, everything else is optional...

I do have a few classes that don't need to have anything passed to
work... It all depends on the implementation and what the class is for.
I set up mutator methods like:
function setHost($x){ $this->host = $x; return TRUE; }
function setUser($x){ $this->user = $x; return TRUE; }
function setPass($x){ $this->passwd = $x; return TRUE; }
function setDB($x){ $this->db = $x; return TRUE; }

As well as accessor methods like:
function getHost($x){ return $this->host; }
function getUser($x){ return $this->user; }
function getPass($x){ return $this->passwd; }
function getDB($x){ return $this->db; }


If your object expose all of it's internal state, it's bad luck. What
happens if you instanciate the object with all parameters and then
change the 'User' field only ?


That was just as example... Again, it depends on what the class
represents and what it is used for.
Then I have the ability to set up utility methods:
function resetConnection(){ return $this->mysqlclass(); }


You don't need to expose all the object's internal state to write this
kind of method :
That way, if you want to change sql servers, you don't need to create
another object, just use something like:

$db->setHost='localhost';
$db->setUser='user';
$db->setPass='passwd';
$db->setDB='database';
$db->resetConnection();


lol, and yuck :(


Funny, huh? Well, this works very well for an online listing class I
have. I use this method to set 3 or 4 options out of the 15 available to
the object at a time. I could set the variables directly, but then if I
want to add functions for checking in the class that's shot.
firstly, i'm afraid this code is awfully broken. Should be :
$db->setHost('localhost');
Ya, I was in a hurry and didn't look over the message...
Then, what happens with this :
$db->setPass('');
$db->resetConnection();
That's what internal class checking is for. In this instance, the
resetConnection might return FALSE and set an error code accessible by
$db->Error();
For this to be not too awful, you'd need :
$db->resetConnection('host', 'user', 'pass', 'db');
No, maybe I only want to change the host, nothing else...
But then - in this particular case - it's just like you've created a new
object :
$db = new Db('host', 'user', 'pass', 'db');
Ya, this was just an illustrative example... I said that in another post.
You'd also be able to get the connection information via the accessor
methods to check what conection you have open.


And if you changed one of the connection information, and then did not
'reset' connection ? out of sync info is worse than no info.


Again, that's where class error handling comes in... has nobody ever
though of that stuff before!?
This method also gives you the ability to change variable names in the
class without effecting the API of it - making it easier to maintain
and sometimes more portable.


Yes, what a great deal... internally rename '$this->user' to
'$this->m_str_user_name' without affecting the 'API' (er...).


Sure, you can just go about assining your variables to user-input
without checking... A more typical mutator would be like this (for example):

function setVariable($x){
if($result=$this->_validate_type($x)){
return TRUE;
}else{
$this->_ERROR=$result*-1;
return FALSE:
}
}
I guess it all depends if you want to go the true OOP route like C++
where there are private and public methods, or like PHP4, where
everything is public.


What is 'public' is what you use outside of the class. What is 'private'
is what you dont use outside of the class. No need to enforce this with
builtin keywords and compiler checks.


The author may know the difference, but if you give it to another
developer, how the hell would they know what they should and shouldn't
use - afterall, the average PHP coder doesn't provide enough
documentation to explain these types of things.
I usually try to stick with the strict C++ methodology in order to
force myself to create better code. (My thinking here is that if I am
forced to create all these methods, I may as well spend the extra few
minutes checking all input and writing error codes and such that re
easier to debug down the road.)


Nothing forces you to write any getter/setter unless the client code
really needs it. Should read the pragmatic programmer's advices :
http://www.pragmaticprogrammer.com/p...s/1998_05.html


Read something very similar to it before...
Now i'm not telling that getter/setter are a Bad Thing by themselves,
just that you should make a distinction between what is the class
'Knowledge Responsability' (ie : what client code is entitled to ask the
class) and what is in fact internal state. If you happen to query the
object about it's internal state just in order to decide what you're
going to tell him to do next, then you've broken encapsulation, and
you'd better fix your code right now. One important rule here is that
you never should bother about the internal state of an object before
sending him a message.


<sic>Next time I won't bother with illustrative examples, I'll just talk
in ways that will confuse the poor OP more and eventually have them give
up on OOP so the rest of us can keep our share...</sic>

Don't read into examples like this just to prove you have a superior
intellect - it turns ppl off.

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.
Official Google SERPs SEO Competition: http://www.koivi.com/serps.php
Jul 17 '05 #10
Pass an associative array to the constructor.

class mysqlclass {
function mysqlclass($params) {
foreach($params as $name => $value) {
$this->$name = $value;
}
}
}

mysqlclass(array(
"host" => "localhost",
"user" => "baby",
"password" => "the_dingo_ate_my_baby",
"database" => "dingo"
));

Uzytkownik "Dan" <ji****@aol.nospam.please.com> napisal w wiadomosci
news:9R7Wb.140966$U%5.645984@attbi_s03...
I have seen differing ways to pass values to a class:

$db=new mysqlclass('localhost','user','passwd','database') ;
....
OR

$db=new mysqlclass()
$db->host='localhost';
$db->user='user';
$db->passwd='passwd';
$db->database='database';
....

To me, the second looks like more typing. But if the argument list to the
class changes, the latter would not be effected. I am trying to drag my
brain (kicking and scratching) into OOP. Any thoughts on this would be
appreciated.

Thanks

Dan

Jul 17 '05 #11
Justin Koivisto <sp**@koivi.com> wrote in message news:<wf****************@news7.onvoy.net>...
Dan wrote:
I have seen differing ways to pass values to a class:

$db=new mysqlclass('localhost','user','passwd','database') ;
....
OR

$db=new mysqlclass()
$db->host='localhost';
$db->user='user';
$db->passwd='passwd';
$db->database='database';


Usually, I use both ways. For instance, in the class constructor, I
allow parameters to be sent as arguements (usually in an array), but
leave them optional.

I set up mutator methods like:
function setHost($x){ $this->host = $x; return TRUE; }
function setUser($x){ $this->user = $x; return TRUE; }
function setPass($x){ $this->passwd = $x; return TRUE; }
function setDB($x){ $this->db = $x; return TRUE; }

As well as accessor methods like:
function getHost($x){ return $this->host; }
function getUser($x){ return $this->user; }
function getPass($x){ return $this->passwd; }
function getDB($x){ return $this->db; }


I have seen few of your classes before. I'm a good fan of your
style. And I prefer getter/setter that make the class highly reusable.
When we need to send so many variables (as in the case of PayPal or
Authorize.net), I would use

function setParameter($key, $value)
{
$this->params[$key] = $value;
}

I have grabbed the above logic from
<http://www.zend.com/codex.php?id=1194&single=1> And now, I use Matt
Babineau's style; I like the underscore functions style to show it is
just internal function.

--
"Success = 10% sweat + 90% tears"
If you live in USA, please support John Edwards.
Email: rrjanbiah-at-Y!com
Jul 17 '05 #12
"Dan" <ji****@aol.nospam.please.com> wrote in message
news:<9R7Wb.140966$U%5.645984@attbi_s03>...

I have seen differing ways to pass values to a class:

$db=new mysqlclass('localhost','user','passwd','database') ;
....
OR

$db=new mysqlclass()
$db->host='localhost';
$db->user='user';
$db->passwd='passwd';
$db->database='database';
....
There's also third way:

$db = new mysqlclass()
$db->sethost('localhost');
$db->setuser('user');
$db->setpasswd('passwd');
$db->setdatabase('database');
To me, the second looks like more typing. But if the argument
list to the class changes, the latter would not be effected.
I am trying to drag my brain (kicking and scratching) into OOP.
Any thoughts on this would be appreciated.


First and foremost, consider not doing any OOP at all. Abstraction
layers in PHP can be a taxing proposition...

Cheers,
NC
Jul 17 '05 #13
Justin Koivisto wrote:
Bruno Desthuilliers wrote:
Justin Koivisto wrote:
Dan wrote:

I have seen differing ways to pass values to a class:

$db=new mysqlclass('localhost','user','passwd','database') ;
....
OR

$db=new mysqlclass()
$db->host='localhost';
$db->user='user';
$db->passwd='passwd';
$db->database='database';
Usually, I use both ways. For instance, in the class constructor, I
allow parameters to be sent as arguements (usually in an array), but
leave them optional.

So the object created without all necessary parameters is not usable.
Bad Thing(tm).

I should have made that more clear. Objects that *need* stuff to work
would have them required, everything else is optional...


Ok, this is somewhat different from what I understood...
I do have a few classes that don't need to have anything passed to
work... It all depends on the implementation and what the class is for.
Of course !-)
I set up mutator methods like: (snip getters/setters)
If your object expose all of it's internal state, it's bad luck. What
happens if you instanciate the object with all parameters and then
change the 'User' field only ?


That was just as example... Again, it depends on what the class
represents and what it is used for.


Ok, but in this case it might have been a bad exemple. Not that this is
'absolutely bad code' - one can't say without knowing the code and
context -, but because it's a bit misleading IMHO. Reading this, the OP
could believe that one needs to have getters/setters for all private
data members of a class.
Then I have the ability to set up utility methods:
function resetConnection(){ return $this->mysqlclass(); }


You don't need to expose all the object's internal state to write this
kind of method :
That way, if you want to change sql servers, you don't need to create
another object, just use something like:

$db->setHost='localhost';
$db->setUser='user';
$db->setPass='passwd';
$db->setDB='database';
$db->resetConnection();

lol, and yuck :(


Funny, huh? Well, this works very well for an online listing class I
have.


Non-OO code can work pretty-well, and be as good and efficient as OO
code !-)
I use this method to set 3 or 4 options out of the 15 available to
the object at a time. I could set the variables directly, but then if I
want to add functions for checking in the class that's shot.
firstly, i'm afraid this code is awfully broken. Should be :
$db->setHost('localhost');


Ya, I was in a hurry and didn't look over the message...


This happens to me too !-)
Then, what happens with this :
$db->setPass('');
$db->resetConnection();


That's what internal class checking is for. In this instance, the
resetConnection might return FALSE and set an error code accessible by
$db->Error();


And you didn't check the return of $db->resetConnection(), did you ?-)
For this to be not too awful, you'd need :
$db->resetConnection('host', 'user', 'pass', 'db');


No, maybe I only want to change the host, nothing else...


Can do this with 'default' values.

class Db {
function resetConnection($host, $user, $pwd, $db) {
if ($host != null) {
/* proceed with $host */
}
if ($user != null) {
/* proceed with user */
}
/* etc ... */
/* and now try and reset the connection */
}
}

Now you have an atomic operation, so
- you do not depend on any previous method calls
- the object's internal state is always 'in sync' with the current
connection

Then I do agree that keyword args would be just fine !-)

(snip)
You'd also be able to get the connection information via the accessor
methods to check what conection you have open.


And if you changed one of the connection information, and then did not
'reset' connection ? out of sync info is worse than no info.


Again, that's where class error handling comes in... has nobody ever
though of that stuff before!?


Why having complex error handling code when a pretty simple API can make
sure such errors won't happen first ?-)

Now with your example, just how would your error handling prevent the
problem ? Given the code you show, when the client code changes some
connection info via a setter and don't call resetConnection(),
connections infos are out of sync wrt the current connection.
This method also gives you the ability to change variable names in
the class without effecting the API of it - making it easier to
maintain and sometimes more portable.


Yes, what a great deal... internally rename '$this->user' to
'$this->m_str_user_name' without affecting the 'API' (er...). Sure, you can just go about assining your variables to user-input
without checking... A more typical mutator would be like this (for
example):

function setVariable($x){
if($result=$this->_validate_type($x)){
return TRUE;
}else{
$this->_ERROR=$result*-1;
return FALSE:
}
}
Well, one of the good things to come with PHP5 are exceptions !-)

Now what I wanted to say is that encapsulation is more than just
wrapping data members access into getters/setters. It's about not
exposing anything that dont need to be exposed.
I guess it all depends if you want to go the true OOP route like C++
where there are private and public methods, or like PHP4, where
everything is public.


What is 'public' is what you use outside of the class. What is
'private' is what you dont use outside of the class. No need to
enforce this with builtin keywords and compiler checks.


The author may know the difference, but if you give it to another
developer, how the hell would they know what they should and shouldn't
use


Some languages seems to go well with just some simple conventions. Like
prefixing protected members with '_' and private members with '__'.
- afterall, the average PHP coder doesn't provide enough
documentation to explain these types of things.
Bad coder, Burn coder !-)

(snip)

<OT> <sic>Next time I won't bother with illustrative examples, I'll just talk
in ways that will confuse the poor OP more
Please do bother with illustrative examples. It just happens that I
found your example actually confusing in some points, and explained why.
This as nothing to do with *you*, so why do you take it that way ? Did I
sound a bit harsh ? Sorry, but English is not my first language, so I
may sometime say things the simplest way. (Feel free to offer me some
English courses so I can express myself in a more subtle manner...)
and eventually have them give
up on OOP so the rest of us can keep our share...</sic>

Don't read into examples like this just to prove you have a superior
intellect - it turns ppl off.


What's you problem, exactly ? Believe it or not, I'm not trying to prove
anything, nor did I attack you, so please let's keep this for what it is
: POW on OO, not a pissing contest. If you want to talk about PHP
programming and/or OO, that's fine with me. Now if you don't stand
criticism, well, too bad, but that's your problem, not mine.
</OT>

Jul 17 '05 #14
Dan
Thanks to all those who replied (and those who replied to the replies).

After 20+ years of various flavors of BASIC, starting with a Sinclair 1000
(I think that was what it was called -- it had 2K RAM! I think I got it
sometime in 1981), I am really enjoying getting to know PHP. I have already
converted a few relatively complex applications from VBScript. These are
all procedural, line-by-line and translations of vb to php. I have many php
books - each with at least one chapter of OOP. I really found it difficult
to understand the advantages, as opposed to simply including files with the
functions I need. I finally just started to DO it, rather than just THINK
about it. These posts were worth more than many chapters in any php book.

Thanks again

Dan


Jul 17 '05 #15

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

Similar topics

2
3323
by: Amit D.Shinde | last post by:
Hello Experts.. I need some help regarding cookies and session objects and also global.asa file I am creating one cookie when a user logs in on my website. The cookie stores the login name of...
6
2129
by: lastusernameleft | last post by:
i've been researching this issue for a while and can't come to any conclusive answer, mostly it seems to be a preference over syntax, some saying c# is elegant while vb is clunky, or that c# is...
1
3464
by: Markus Rebbert | last post by:
Hi list, i got an postgresql installation on linux (debian) with the htree partitions: 1- system 2- postgresql data files 3- postgresql WAL logs(pg_xferlog) Our standard file system is...
4
2924
by: Ed Davis | last post by:
I'm trying to decide which of the following programming styles is better, as in easier to understand, and thus easier to maintain. Keep in mind that for posting purposes, this is a greatly...
9
288
by: Robert Lario | last post by:
C# verses VB.Net Which Way to go. I am sure this issues has come up before. Please direct me to any good articles that cover this issue. Ideally some neutral assessment.
22
2197
by: smartwolf agassi via DotNetMonster.com | last post by:
I'm a C# language learner. I want to know which IDE is better for C# programing, Borland C#Builder or VS.net 2003? -- Message posted via http://www.dotnetmonster.com
2
2880
by: monkeydragon | last post by:
Which is better, using ReadFile/WriteFile or use fstream?
33
2523
by: Protoman | last post by:
Which is better for general-purpose programming, C or C++? My friend says C++, but I'm not sure. Please enlighten me. Thanks!!!!!
48
4882
by: meyer | last post by:
Hi everyone, which compiler will Python 2.5 on Windows (Intel) be built with? I notice that Python 2.4 apparently has been built with the VS2003 toolkit compiler, and I read a post from Scott...
20
3043
by: mike3 | last post by:
Hi. (Xposted to both comp.lang.c++ and comp.programming since I've got questions related to both C++ language and general programming) I've got the following C++ code. The first routine runs in...
0
7220
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
7105
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...
0
7308
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
7479
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
5617
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,...
0
4702
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...
0
3188
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...
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
757
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.