RE: [PHP] Classes - Dumb question

2007-10-15 Thread Jay Blanchard
[snip]
With a class you can inherit all of the base class functionality 
into a new customer type. You do not have to break open the base 
class to add a case, you just have to create an extension class. 
Documentation is unique to each class.

No matter what, you have to break something open to add code -- if 
nothing else, the script.
[/snip]

The base class would (should?) be contained in its own script space. For 
instance you might have the customer class in a file called class.customer.php. 
You do not have to open this script to add another class or extend this class, 
you would just add another file like class.customerCommercial.php that extends 
the customer class. Since autoload is available now 
(http://www.php.net/autoload) you would not even have to open the 'calling' 
script to add an include line.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Classes - Dumb question

2007-10-15 Thread Nathan Nobbe
On 10/15/07, Jay Blanchard [EMAIL PROTECTED] wrote:

 [snip]
 With a class you can inherit all of the base class functionality
 into a new customer type. You do not have to break open the base
 class to add a case, you just have to create an extension class.
 Documentation is unique to each class.

 No matter what, you have to break something open to add code -- if
 nothing else, the script.
 [/snip]

 The base class would (should?) be contained in its own script space. For
 instance you might have the customer class in a file called
 class.customer.php. You do not have to open this script to add another
 class or extend this class, you would just add another file like
 class.customerCommercial.php that extends the customer class. Since
 autoload is available now (http://www.php.net/autoload) you would not even
 have to open the 'calling' script to add an include line.


furthermore using a delegation technique like Stut demonstrated,
you may not even need to edit a file to instantiate the class and call a
method.

-nathan


RE: [PHP] Classes - Dumb question

2007-10-15 Thread tedd

At 5:42 AM -0500 10/15/07, Jay Blanchard wrote:

[snip]

With a class you can inherit all of the base class functionality
into a new customer type. You do not have to break open the base
class to add a case, you just have to create an extension class.
Documentation is unique to each class.


No matter what, you have to break something open to add code -- if
nothing else, the script.
[/snip]

The base class would (should?) be contained in its own script space. 
For instance you might have the customer class in a file called 
class.customer.php. You do not have to open this script to add 
another class or extend this class, you would just add another file 
like class.customerCommercial.php that extends the customer class. 
Since autoload is available now (http://www.php.net/autoload) you 
would not even have to open the 'calling' script to add an include 
line.


I understand the class concept. But, I am not familiar with autoload.

Stut also made mention of that, so I shall investigate post haste.

Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Classes - Dumb question

2007-10-15 Thread Nathan Nobbe
On 10/15/07, tedd [EMAIL PROTECTED] wrote:

 I understand the class concept. But, I am not familiar with autoload.

 Stut also made mention of that, so I shall investigate post haste.


__autoload is pretty tight; but if you dont want to have all your class
files in the same
directory, i suggest you implement something custom.
ive seen several implementations where class names basically have filesystem
paths
embedded in them; ugh..  i think thats what those buxa project guys are
doing, but im
not certain.
also, the __autoload() function has to be available for it to be called,
which means you
will have to include the file that defines it in every file that would use
it.  since my php
code is heavily oop; i just use the php.ini auto_prepend_file directive.
oh; btw, Tedd, autoload is for classes only; if you like what you see maybe
that will be
the excuse youve been looking for to get into oop w/ php :)

-nathan


Re: [PHP] Classes - Dumb question

2007-10-15 Thread Larry Garfield
On Monday 15 October 2007, Nathan Nobbe wrote:
 On 10/15/07, tedd [EMAIL PROTECTED] wrote:
  I understand the class concept. But, I am not familiar with autoload.
 
  Stut also made mention of that, so I shall investigate post haste.

 __autoload is pretty tight; but if you dont want to have all your class
 files in the same
 directory, i suggest you implement something custom.
 ive seen several implementations where class names basically have
 filesystem paths
 embedded in them; ugh..  i think thats what those buxa project guys are
 doing, but im
 not certain.
 also, the __autoload() function has to be available for it to be called,
 which means you
 will have to include the file that defines it in every file that would use
 it.  since my php
 code is heavily oop; i just use the php.ini auto_prepend_file directive.
 oh; btw, Tedd, autoload is for classes only; if you like what you see maybe
 that will be
 the excuse youve been looking for to get into oop w/ php :)

 -nathan

__autoload() is also not recommended. :-)  You can only have one per script.  
Instead, use spl_autoload_register().  That way you can stack multiple 
autoload routines cleanly.

(At least that's what the php-internals folks were saying the last time the 
topic came up.)

http://us2.php.net/manual/en/function.spl-autoload-register.php

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it.  -- Thomas 
Jefferson

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Classes - Dumb question

2007-10-15 Thread Nathan Nobbe
On 10/15/07, Larry Garfield [EMAIL PROTECTED] wrote:

 On Monday 15 October 2007, Nathan Nobbe wrote:
  On 10/15/07, tedd [EMAIL PROTECTED] wrote:
   I understand the class concept. But, I am not familiar with autoload.
  
   Stut also made mention of that, so I shall investigate post haste.
 
  __autoload is pretty tight; but if you dont want to have all your class
  files in the same
  directory, i suggest you implement something custom.
  ive seen several implementations where class names basically have
  filesystem paths
  embedded in them; ugh..  i think thats what those buxa project guys are
  doing, but im
  not certain.
  also, the __autoload() function has to be available for it to be called,
  which means you
  will have to include the file that defines it in every file that would
 use
  it.  since my php
  code is heavily oop; i just use the php.ini auto_prepend_file directive.
  oh; btw, Tedd, autoload is for classes only; if you like what you see
 maybe
  that will be
  the excuse youve been looking for to get into oop w/ php :)
 
  -nathan

 __autoload() is also not recommended. :-)  You can only have one per
 script.
 Instead, use spl_autoload_register().  That way you can stack multiple
 autoload routines cleanly.

 (At least that's what the php-internals folks were saying the last time
 the
 topic came up.)

 http://us2.php.net/manual/en/function.spl-autoload-register.php


neat; i didnt know about that, but i had checked out spl_autoload() before.
ive defined a singleton that has a method for loading of classpaths.
when __autoload is called, it delegates to the singleton to see if the
classpath is valid.
if theres a match it loads it, otherwise it chokes.
i cant imagine having multiple __autoload methods, but perhaps if there was
a third party
lib that was also using autoload() theirs could be stacked on top of yours
and that way they
could both live together.  i might give that a shot.

-nathan


Re: [PHP] Classes - Dumb question

2007-10-13 Thread Christian Hänsel


Jay Blanchard [EMAIL PROTECTED] schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]

[snip]

First of all what you call normal is procedural or functional
programming. There is nothing wrong with doing things this way and may

be

especially quick and efficient when doing basic web sites and

applications.

Document well and you will have no problem maintaining your code.


One correction.  What is being described is procedural or imperative
programming.  Functional programming is another beast entirely
(closures,
first-class functions, immutable variables, etc.).  PHP is not a
functional
language by any stretch of the imagination.  For functional programming,
see
Erlang, Haskel, ML, LISP, and to a lesser extent Javascript.
[/snip]


Thanks for the correction Larry, I knew the difference and just brain
farted.


Thanks guys,

I will try to test some of this stuff for my new project... could be fun 
from what I have seen so far.


Cheers!

Chris

--
-
My baby's first words will be
Hello World

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Classes - Dumb question

2007-10-12 Thread Nathan Nobbe
On 10/12/07, Larry Garfield [EMAIL PROTECTED] wrote:

 On Thursday 11 October 2007, Jay Blanchard wrote:
  [snip]
  okay, this is really (!) embarassing, but I have to ask:
 
  Why would I want to use classes in PHP?
 
  I have been using PHP for years now and writing the normal functions
 all
  the time. I have never even bothered working with classes, but now I
 would
  love to know what makes the classes so special...
 
  Please go easy on me ;o) Just trying to make another step :o)
  [/snip]
 
  Do not be embarrassed, this is a very good question.
 
  First of all what you call normal is procedural or functional
  programming. There is nothing wrong with doing things this way and may
 be
  especially quick and efficient when doing basic web sites and
 applications.
  Document well and you will have no problem maintaining your code.

 One correction.  What is being described is procedural or imperative
 programming.  Functional programming is another beast entirely (closures,
 first-class functions, immutable variables, etc.).  PHP is not a
 functional
 language by any stretch of the imagination.  For functional programming,
 see
 Erlang, Haskel, ML, LISP, and to a lesser extent Javascript.

 That's not a knock against PHP, mind you; I'm just pointing out that
 functional programming is something different than what you are
 describing.
 It's a common point of confusion because in a procedural language
 (traditional PHP, C, etc.) you do everything with functions, so it's
 functional.  The difference is that a function is not a base data type,
 which is a key component of a functional language.


an aspect that makes working with javascript rather interesting.  i get my
fill of
it there and enjoy php for what it is; and because its more familiar to me
;)

-nathan


Re: [PHP] Classes - Dumb question

2007-10-12 Thread Stut

tedd wrote:

function customer($whatWas, $customertype, $whatAdditional)
   {
   /* do what was (i.e., common to all) */
   /* then do what's additional unique to type */
   switch(1)
   {
   case $customertype =='Commercial':
   commercialCustomer($whatAdditional);
   break;

.. and so on
   }

function commercialCustomer($whatAdditional)
   {
   /*
   *only code unique to commercial customers
*/
   }

function militaryCustomer($whatAdditional)
   {
   /*
   *only code unique to military customers
   */
   }

In either case, I still have to write more code to accommodate scaling. 
And, if I have more customer types, then it's a simple matter to add 
more customer functions and addition case statements to the initial 
customer function. I don't see the benefit in using a class. At this 
point, it just looks like a different way of doing things.


You can limit the need to add more code like so...

function customer($whatWas, $customertype, $whatAdditional)
{
/* do what was (i.e., common to all) */
/* then do what's additional unique to type */
$func = strtolower($customertype).'Customer';
$func($whatAdditional);
}

You could do (and I have done) something similar with classes.

For me the biggest benefit of using OOP is __autoload(). It makes life 
so much easier.


-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Classes - Dumb question

2007-10-12 Thread Nathan Nobbe
On 10/12/07, Jay Blanchard [EMAIL PROTECTED] wrote:

 No doubt. (are you by chance continuing the other argument, re:
 interfaces?), but you have to break open the original tested function, add
 code to it, test it, etc. Every time you add a new case you have to break
 open the existing function to add that case. After a while, say if you need
 to drop a customer type you would have to (not really, you can leave it
 there and never exercise the case) break open the original code and delete
 the un-used code. Any way that you slice it the original customer function
 becomes more and more like spaghetti every day. Documentation for the
 function has to change each time as well.

 With a class you can inherit all of the base class functionality into a
 new customer type. You do not have to break open the base class to add a
 case, you just have to create an extension class. Documentation is unique to
 each class.


Stut has demonstrated an example of delegation.  when used with objects,
inheritance is not necessary, but it can be used if desired.
use your polymorphic mechanism of choice :)

-nathan


RE: [PHP] Classes - Dumb question

2007-10-12 Thread Jay Blanchard
[snip]
 First of all what you call normal is procedural or functional
 programming. There is nothing wrong with doing things this way and may
be
 especially quick and efficient when doing basic web sites and
applications.
 Document well and you will have no problem maintaining your code.

One correction.  What is being described is procedural or imperative 
programming.  Functional programming is another beast entirely
(closures, 
first-class functions, immutable variables, etc.).  PHP is not a
functional 
language by any stretch of the imagination.  For functional programming,
see 
Erlang, Haskel, ML, LISP, and to a lesser extent Javascript.  
[/snip]

Thanks for the correction Larry, I knew the difference and just brain
farted. 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Classes - Dumb question

2007-10-12 Thread Jay Blanchard
[snip]
Yes, but I could do that procedurally from within the customer 
function by simply adding a customer type (needed regardless) and 
using a switch to direct and collect the additional data needed.




In either case, I still have to write more code to accommodate 
scaling. And, if I have more customer types, then it's a simple 
matter to add more customer functions and addition case statements to 
the initial customer function. I don't see the benefit in using a 
class. At this point, it just looks like a different way of doing 
things.
[/snip]

No doubt. (are you by chance continuing the other argument, re: interfaces?), 
but you have to break open the original tested function, add code to it, test 
it, etc. Every time you add a new case you have to break open the existing 
function to add that case. After a while, say if you need to drop a customer 
type you would have to (not really, you can leave it there and never exercise 
the case) break open the original code and delete the un-used code. Any way 
that you slice it the original customer function becomes more and more like 
spaghetti every day. Documentation for the function has to change each time as 
well.

With a class you can inherit all of the base class functionality into a new 
customer type. You do not have to break open the base class to add a case, you 
just have to create an extension class. Documentation is unique to each class.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Classes - Dumb question

2007-10-12 Thread tedd

At 7:36 AM -0500 10/11/07, Jay Blanchard wrote:

[snip]
okay, this is really (!) embarassing, but I have to ask:

Why would I want to use classes in PHP?

I have been using PHP for years now and writing the normal functions all
the time. I have never even bothered working with classes, but now I would
love to know what makes the classes so special...

Please go easy on me ;o) Just trying to make another step :o)
[/snip]

Do not be embarrassed, this is a very good question.

First of all what you call normal is procedural or functional 
programming. There is nothing wrong with doing things this way and 
may be especially quick and efficient when doing basic web sites and 
applications. Document well and you will have no problem maintaining 
your code.


OOP (object oriented programming) is especially useful when the 
application you have created needs to scale. A quick example; you 
have sold your products to the consumer market for a long time but 
now the commercial market has become interested. Commercial 
customers are different than non-commercial customers, different 
data, different credit requirements, different shipping, etc. but 
they still have a lot in common, If you had a class Customer you 
could extended that class to include commercial customers and only 
have to code for the unique qualities of that kind of customer. Then 
if another type of customer crops up, say a military contract, you 
could extend again;


class Customer {

}

class CommercialCustomer extends Customer {
/*
 *only code unique to commercial customers
 * inherits from Customer other variables
 * and functions that are common
 */
}

class MilitaryCustomer extends Customer {
/*
 *only code unique to military customers
 * inherits from Customer other variables
 * and functions that are common
 */
}


Jay:

Yes, but I could do that procedurally from within the customer 
function by simply adding a customer type (needed regardless) and 
using a switch to direct and collect the additional data needed.


function customer($whatWas, $customertype, $whatAdditional)
   {
   /* do what was (i.e., common to all) */
   /* then do what's additional unique to type */
   switch(1)
   {
   case $customertype =='Commercial':
   commercialCustomer($whatAdditional);
   break;

.. and so on
   }

function commercialCustomer($whatAdditional)
   {
   /*
   *only code unique to commercial customers
*/
   }

function militaryCustomer($whatAdditional)
   {
   /*
   *only code unique to military customers
   */
   }

In either case, I still have to write more code to accommodate 
scaling. And, if I have more customer types, then it's a simple 
matter to add more customer functions and addition case statements to 
the initial customer function. I don't see the benefit in using a 
class. At this point, it just looks like a different way of doing 
things.


Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Classes - Dumb question

2007-10-12 Thread tedd

At 2:44 PM +0100 10/12/07, Stut wrote:

You can limit the need to add more code like so...

function customer($whatWas, $customertype, $whatAdditional)
{
/* do what was (i.e., common to all) */
/* then do what's additional unique to type */
$func = strtolower($customertype).'Customer';
$func($whatAdditional);
}


That's something I haven't seen before (in this language) -- that's slick.

Thanks,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Classes - Dumb question

2007-10-12 Thread tedd

At 9:03 AM -0500 10/12/07, Jay Blanchard wrote:

tedd said:

In either case, I still have to write more code to accommodate
scaling. And, if I have more customer types, then it's a simple
matter to add more customer functions and addition case statements to
the initial customer function. I don't see the benefit in using a
class. At this point, it just looks like a different way of doing
things.
[/snip]


No doubt. (are you by chance continuing the other argument, re: interfaces?)


No, I didn't really understand the argument anyway. An interface to 
me currently is what the user uses to trigger my scripts.


, but you have to break open the original tested function, add code 
to it, test it, etc. Every time you add a new case you have to break 
open the existing function to add that case. After a while, say if 
you need to drop a customer type you would have to (not really, you 
can leave it there and never exercise the case) break open the 
original code and delete the un-used code. Any way that you slice it 
the original customer function becomes more and more like spaghetti 
every day. Documentation for the function has to change each time as 
well.


Every time you add more code, the documentation should change regardless.

Every time you add more code, you have to test it anyway.

Spaghetti is not caused by adding more code, but by poor design.

With a class you can inherit all of the base class functionality 
into a new customer type. You do not have to break open the base 
class to add a case, you just have to create an extension class. 
Documentation is unique to each class.


No matter what, you have to break something open to add code -- if 
nothing else, the script.


I do see and understand the methodology afforded by OOP, but, I don't 
see an overwhelming reason to use it. Maybe in my next decade of 
programming I'll get with the program. After all, I don't keypunch 
anymore and that's progress. :-)


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Classes - Dumb question

2007-10-11 Thread Christian Hänsel

Howdy fellas,

okay, this is really (!) embarassing, but I have to ask:

Why would I want to use classes in PHP?

I have been using PHP for years now and writing the normal functions all 
the time. I have never even bothered working with classes, but now I would 
love to know what makes the classes so special...


Please go easy on me ;o) Just trying to make another step :o)

Cheerio, and thanks in advance for any answers.

Chris 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Classes - Dumb question

2007-10-11 Thread Jay Blanchard
[snip]
okay, this is really (!) embarassing, but I have to ask:

Why would I want to use classes in PHP?

I have been using PHP for years now and writing the normal functions all 
the time. I have never even bothered working with classes, but now I would 
love to know what makes the classes so special...

Please go easy on me ;o) Just trying to make another step :o)
[/snip]

Do not be embarrassed, this is a very good question.

First of all what you call normal is procedural or functional programming. 
There is nothing wrong with doing things this way and may be especially quick 
and efficient when doing basic web sites and applications. Document well and 
you will have no problem maintaining your code.

OOP (object oriented programming) is especially useful when the application you 
have created needs to scale. A quick example; you have sold your products to 
the consumer market for a long time but now the commercial market has become 
interested. Commercial customers are different than non-commercial customers, 
different data, different credit requirements, different shipping, etc. but 
they still have a lot in common, If you had a class Customer you could extended 
that class to include commercial customers and only have to code for the unique 
qualities of that kind of customer. Then if another type of customer crops up, 
say a military contract, you could extend again;

class Customer {

}

class CommercialCustomer extends Customer {
/* 
 *only code unique to commercial customers
 * inherits from Customer other variables
 * and functions that are common
 */
}

class MilitaryCustomer extends Customer {
/* 
 *only code unique to military customers
 * inherits from Customer other variables
 * and functions that are common
 */
}

http://www.sitepoint.com/article/object-oriented-php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Classes - Dumb question

2007-10-11 Thread Robert Cummings
On Thu, 2007-10-11 at 07:36 -0500, Jay Blanchard wrote:
 [snip]
 okay, this is really (!) embarassing, but I have to ask:
 
 Why would I want to use classes in PHP?
 
 I have been using PHP for years now and writing the normal functions all 
 the time. I have never even bothered working with classes, but now I would 
 love to know what makes the classes so special...
 
 Please go easy on me ;o) Just trying to make another step :o)
 [/snip]
 
 Do not be embarrassed, this is a very good question.
 
 First of all what you call normal is procedural or functional programming. 
 There is nothing wrong with doing things this way and may be especially quick 
 and efficient when doing basic web sites and applications. Document well and 
 you will have no problem maintaining your code.
 
 OOP (object oriented programming) is especially useful when the application 
 you have created needs to scale. A quick example; you have sold your products 
 to the consumer market for a long time but now the commercial market has 
 become interested. Commercial customers are different than non-commercial 
 customers, different data, different credit requirements, different shipping, 
 etc. but they still have a lot in common, If you had a class Customer you 
 could extended that class to include commercial customers and only have to 
 code for the unique qualities of that kind of customer. Then if another type 
 of customer crops up, say a military contract, you could extend again;
 
 class Customer {
   
 }
 
 class CommercialCustomer extends Customer {
   /* 
*only code unique to commercial customers
* inherits from Customer other variables
* and functions that are common
*/
 }
 
 class MilitaryCustomer extends Customer {
   /* 
*only code unique to military customers
* inherits from Customer other variables
* and functions that are common
*/
 }
 
 http://www.sitepoint.com/article/object-oriented-php

Another good reason is for function/data grouping. By using a class you
don't have to worry about name collisions for your functions, although
you can still have class name collisions. Also, data related to any
operations can be tracked via the object rather than cluttering the
global namespace between function calls.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Classes - Dumb question

2007-10-11 Thread Jason Pruim


On Oct 11, 2007, at 8:36 AM, Jay Blanchard wrote:


[snip]
okay, this is really (!) embarassing, but I have to ask:

Why would I want to use classes in PHP?

I have been using PHP for years now and writing the normal  
functions all
the time. I have never even bothered working with classes, but now  
I would

love to know what makes the classes so special...

Please go easy on me ;o) Just trying to make another step :o)
[/snip]

Do not be embarrassed, this is a very good question.

First of all what you call normal is procedural or functional  
programming. There is nothing wrong with doing things this way and  
may be especially quick and efficient when doing basic web sites  
and applications. Document well and you will have no problem  
maintaining your code.


OOP (object oriented programming) is especially useful when the  
application you have created needs to scale. A quick example; you  
have sold your products to the consumer market for a long time but  
now the commercial market has become interested. Commercial  
customers are different than non-commercial customers, different  
data, different credit requirements, different shipping, etc. but  
they still have a lot in common, If you had a class Customer you  
could extended that class to include commercial customers and only  
have to code for the unique qualities of that kind of customer.  
Then if another type of customer crops up, say a military contract,  
you could extend again;


class Customer {

}

class CommercialCustomer extends Customer {
/*
 *only code unique to commercial customers
 * inherits from Customer other variables
 * and functions that are common
 */
}

class MilitaryCustomer extends Customer {
/*
 *only code unique to military customers
 * inherits from Customer other variables
 * and functions that are common
 */
}

http://www.sitepoint.com/article/object-oriented-php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Not trying to hijack the thread... Hopefully this is related enough,  
if not I apologize. Would a good use of a class be to write a generic  
database connection script? and then feed in the different variables,  
such as customer login, database, stuff like that?


something like class DBConnect {
// Connect to database
mysql_connect($server, $login, $password, $database);
}

or no?
--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
[EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Classes - Dumb question

2007-10-11 Thread Jay Blanchard
[snip]
Not trying to hijack the thread... Hopefully this is related enough,  
if not I apologize. Would a good use of a class be to write a generic  
database connection script? and then feed in the different variables,  
such as customer login, database, stuff like that?

something like class DBConnect {
// Connect to database
mysql_connect($server, $login, $password, $database);
}

or no?
[/snip]

I don't think so because it is inefficient...wrapping an existing stand-alone 
function is sort of redundant. If you were writing a database abstraction layer 
that would be a horse of a different color.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Classes - Dumb question

2007-10-11 Thread Larry Garfield
On Thursday 11 October 2007, Jay Blanchard wrote:
 [snip]
 okay, this is really (!) embarassing, but I have to ask:

 Why would I want to use classes in PHP?

 I have been using PHP for years now and writing the normal functions all
 the time. I have never even bothered working with classes, but now I would
 love to know what makes the classes so special...

 Please go easy on me ;o) Just trying to make another step :o)
 [/snip]

 Do not be embarrassed, this is a very good question.

 First of all what you call normal is procedural or functional
 programming. There is nothing wrong with doing things this way and may be
 especially quick and efficient when doing basic web sites and applications.
 Document well and you will have no problem maintaining your code.

One correction.  What is being described is procedural or imperative 
programming.  Functional programming is another beast entirely (closures, 
first-class functions, immutable variables, etc.).  PHP is not a functional 
language by any stretch of the imagination.  For functional programming, see 
Erlang, Haskel, ML, LISP, and to a lesser extent Javascript.  

That's not a knock against PHP, mind you; I'm just pointing out that 
functional programming is something different than what you are describing.  
It's a common point of confusion because in a procedural language 
(traditional PHP, C, etc.) you do everything with functions, so it's 
functional.  The difference is that a function is not a base data type, 
which is a key component of a functional language.

/semantic nitpick

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it.  -- Thomas 
Jefferson

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php