Re: php 5 classes: public, protected and private



jopperdepopper wrote:
Look for some good books on OO theory and design.



Thanks Jerry, maybe the php 5 approach is a better implementation than
the php 4 approach? I have always felt that in php 4 using classes (or
at least my way of using them) was more a convenient way to organise
code, grouping some related functions in one class, other related ones
in another...

Gotta get me some books & hope it's going to be a loooong coooold
winter ;)


Yes, I think it is - but then I've been doing OO programming for a number of years, both in C++ and Java.

Classes are a good way to organize code - but more importantly, they are a way of organizing code AND DATA. A properly constructed class should, as much as possible, manage it's own data independent of other classes and code.

It's a whole different way of thinking which is usually quite a jump for experienced programmers. In fact, I find newer programmers typically have less problems, because structured code techniques are not so deeply ingrained in their mind. :-)

But it's well worth it; the resulting code can be much more readable and maintainable.

A good example. I needed to implement some pages based on a database. However, the particular host being used at the time did not have MySQL available (they claimed they did, but it wasn't very reliable...).

So I implemented the code in flat files using a class for the data being displayed, and pages to use that class. Later, when they changed to a host which had MySQL, all I had to do was go back to the class and change it to read from a database instead of a flat file. No changes to the pages were needed at all. Very clean and easy to do, because I segregated the operations on the data in the class, and used the web page code just to display the data.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • Re: Post with redirect?
    ... So far you haven't shown us how do to it in PHP. ... You are backpeddling, troll. ... And you're also afraid we will find out you're not a programmer with 25 years of experience. ... the only thing jerry got right is that it would be a lot of work. ...
    (comp.lang.php)
  • Re: Post with redirect?
    ... He wanted a way to redirect a port with data to an external site ... posting certain inputs, with the 3rd party server as the target. ... i made no claim other than you can use just php to get the job done. ... only thing jerry got right is that it would be a lot of work. ...
    (comp.lang.php)
  • Re: PHP forms completely blank
    ... When I run the php script the resulting web page is blank. ... #check email useraddr field is not blank ... I guess the main thing that has helped (thanks Jerry) is to turn error logging on & now I am getting an error response from the parser: ...
    (alt.php)
  • Re: Post with redirect?
    ... i made no claim other than you can use just php to get the job done. ... You are backpeddling, troll. ... thing jerry got right is that it would be a lot of work. ... 'it' would be the operative here, jer. ...
    (comp.lang.php)
  • Re: Post with redirect?
    ... you made it about javascript, ... He wanted a way to redirect a port with data to an external site and I gave it to him. ... And you still haven't showed us how to do a redirect with post values in PHP. ... the only thing jerry got right is that it would be a lot of work. ...
    (comp.lang.php)