RE: [PHP] Classes - Dumb question

This is a discussion on RE: [PHP] Classes - Dumb question within the PHP General forums, part of the PHP Programming Forums category; [snip] >With a class you can inherit all of the base class functionality >into a new customer type. ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-15-2007
Jay Blanchard
 
Posts: n/a
Default RE: [PHP] Classes - Dumb question

[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.
Reply With Quote
  #2 (permalink)  
Old 10-15-2007
Nathan Nobbe
 
Posts: n/a
Default Re: [PHP] Classes - Dumb question

On 10/15/07, Jay Blanchard <jblanchard@pocket.com> 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

Reply With Quote
  #3 (permalink)  
Old 10-15-2007
Nathan Nobbe
 
Posts: n/a
Default Re: [PHP] Classes - Dumb question

On 10/15/07, tedd <tedd@sperling.com> 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

Reply With Quote
  #4 (permalink)  
Old 10-16-2007
Larry Garfield
 
Posts: n/a
Default Re: [PHP] Classes - Dumb question

On Monday 15 October 2007, Nathan Nobbe wrote:
> On 10/15/07, tedd <tedd@sperling.com> 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/functio...d-register.php

--
Larry Garfield AIM: LOLG42
larry@garfieldtech.com 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
Reply With Quote
  #5 (permalink)  
Old 10-16-2007
Nathan Nobbe
 
Posts: n/a
Default Re: [PHP] Classes - Dumb question

On 10/15/07, Larry Garfield <larry@garfieldtech.com> wrote:
>
> On Monday 15 October 2007, Nathan Nobbe wrote:
> > On 10/15/07, tedd <tedd@sperling.com> 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/functio...d-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

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:55 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0