php-general Digest 16 Apr 2008 07:38:46 -0000 Issue 5407
Topics (messages 273009 through 273030):
getting funny error on working page
273009 by: John A DAVIS
273010 by: Daniel Brown
273013 by: John A DAVIS
273015 by: Andrew Ballard
273023 by: Daniel Brown
Re: Quarters
273011 by: tedd
273012 by: Daniel Brown
273014 by: Wolf
273017 by: tedd
Re: Most viewed?
273016 by: tedd
PHP Speech
273018 by: tedd
273022 by: Daniel Brown
Forking and fsock
273019 by: Kyle Browning
273020 by: Jason Knight
PHP with NNTP?
273021 by: vester_s
273027 by: Per Jessen
273028 by: Chris
273030 by: Crayon Shin Chan
Re: What is the practical use of "abstract" and "interface"?
273024 by: Larry Garfield
273025 by: Shawn McKenzie
273026 by: Daevid Vincent
273029 by: Larry Garfield
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
|
I've upgraded my PHP install and now I get this error in my test environment so I'm scared to load any changes up to the production website where this error doesn't exist. What is funny is the page still runs and lists all the data in correct rows, but with an error for each row right at the top of the page.
Notice: A non well formed numeric value encountered in C:\Inetpub\wwwroot\mazamaslocal\functions.php on line 15 Oct 02 (Tue) Triple Crown Ken Searl
Here is the function
*************************************
function fMakeWideDate($thisdate,$senderformat) { //parameters: //1 for mm/dd/yyyy date format sent in //2 for yyyy/mm/dd date format sent in //this: fWideDate('12/04/2005',1) returns: Dec 04, 2005 (Sun) //this: fWideDAte('2005-12-04',2) returns: Dec 04, 2005 (Sun) if($senderformat==1) //mmddyyyy { $month=substr($thisdate,0,2); $day =substr($thisdate,3,2); $year = substr($thisdate,6,4); $d =date("M d (D)",Mktime(0,0,0,$month,$day,$year)); <<<<<<< line 15 errors here (Oct 02 (Tue) ) //echo $d; //$d =date("M d, Y (D)",Mktime(0,0,0,$month,$day,$year)); } elseif($senderformat==2) //yyyymmdd with dashes { $year = substr($thisdate,0,4); $month=substr($thisdate,5,2); $day =substr($thisdate,8,2); $d =date("M d (D)",Mktime(0,0,0,$month,$day,$year)); } return $d; }
**********************************************
Here is what calls the function basically displaying a userfriendly date //////////////////////////////////////////////////////////////////////////// //LAY OUT THE ROWS WITH INFO HERE /////////////////////////////////////////////////////////////////////////// $fields=mysql_num_fields($data); { for($i=1 ; $i<=$fields-16; $i++) { if($i==3) //DISPLAY DATE { $WideDate=fMakeWideDate($row[$i],1); echo "<td class=\"fatcell\" >".$WideDate."</td>"; } |
--- End Message ---
--- Begin Message ---
On Tue, Apr 15, 2008 at 5:07 PM, John A DAVIS <[EMAIL PROTECTED]> wrote:
[snip!]
>
> Notice: A non well formed numeric value encountered in
> C:\Inetpub\wwwroot\mazamaslocal\functions.php on line 15
> Oct 02 (Tue) Triple Crown Ken Searl
It's an E_NOTICE. That means the issue has always existed, it was
just never displayed. While you should make every attempt to fix
every issue, notices are generally safe to ignore without any serious
consequence (keep in mind, I say, "generally"). So you can update
your php.ini's error_reporting variable to the following:
error_reporting = E_ALL & ~E_NOTICE
.... and then restart IIS (which is what it looks like you're
using, based upon path).
--
</Daniel P. Brown>
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!
--- End Message ---
--- Begin Message ---
|
Thanks! My guess is the production server has this set correctly and I will follow your advice.
However, how would one do away with this error? What would I do to guarantee an string being returned instead of a date? What can I wrap the date() function in?
$month=substr($thisdate,0,2); $day =substr($thisdate,3,2); $year = substr($thisdate,6,4);
$d =date("M d (D)",Mktime(0,0,0,$month,$day,$year));
Again, thank you!
John A. Davis
>>> "Daniel Brown" <[EMAIL PROTECTED]> 4/15/2008 2:14:16 PM >>>
On Tue, Apr 15, 2008 at 5:07 PM, John A DAVIS <[EMAIL PROTECTED]> wrote: [snip!] > > Notice: A non well formed numeric value encountered in > C:\Inetpub\wwwroot\mazamaslocal\functions.php on line 15 > Oct 02 (Tue) Triple Crown Ken Searl
It's an E_NOTICE. That means the issue has always existed, it was just never displayed. While you should make every attempt to fix every issue, notices are generally safe to ignore without any serious consequence (keep in mind, I say, "generally"). So you can update your php.ini's error_reporting variable to the following:
error_reporting = E_ALL & ~E_NOTICE
.... and then restart IIS (which is what it looks like you're using, based upon path).
-- </Daniel P. Brown> Ask me about: Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo., and shared hosting starting @ $2.50/mo. Unmanaged, managed, and fully-managed!
|
--- End Message ---
--- Begin Message ---
On Tue, Apr 15, 2008 at 5:24 PM, John A DAVIS <[EMAIL PROTECTED]> wrote:
>
>
> Thanks! My guess is the production server has this set correctly and I will
> follow your advice.
> However, how would one do away with this error? What would I do to guarantee
> an string being returned instead of a date? What can I wrap the date()
> function in?
>
> $month=substr($thisdate,0,2);
> $day =substr($thisdate,3,2);
> $year = substr($thisdate,6,4);
>
> $d =date("M d (D)",Mktime(0,0,0,$month,$day,$year));
>
>
> Again, thank you!
> John A. Davis
I don't think you need to wrap date() in anything, as it should be
returning a string. Without seeing the actual input that caused the
warning, I think it's probably more an issue with either $month, $day,
or $year not being quite right (but close enough that PHP can still
obtain the correct result). Is it possible (since you're getting the
date from a database query) that the value is coming back as a
datetime string that includes a time portion? Your function should
work OK if you are getting something that looks like '10-02-2008
10:15:27' but will get the error you reported if it gets the same
value as '10022008 10:15:27'. Try doing a var_dump on each value to
make sure it's what you expect it to be.
Andrew
--- End Message ---
--- Begin Message ---
On Tue, Apr 15, 2008 at 5:24 PM, John A DAVIS <[EMAIL PROTECTED]> wrote:
>
>
> Thanks! My guess is the production server has this set correctly and I will
> follow your advice.
> However, how would one do away with this error? What would I do to guarantee
> an string being returned instead of a date? What can I wrap the date()
> function in?
>
>
> $month=substr($thisdate,0,2);
> $day =substr($thisdate,3,2);
> $year = substr($thisdate,6,4);
>
> $d =date("M d (D)",Mktime(0,0,0,$month,$day,$year));
Sorry, my Xorg crashed. A word of wisdom: don't try the new
Compiz-Fusion on KDE with dual-headed setups yet. Let the bugs get
worked out first (or risk having a conspicuous hole in the wall the
size of your forehead like I will in a few days).
To your issue:
* What are you passing to parameter #1 of fMakeWideDate()
(then dubbed $thisdate)?
* Mktime() should be mktime(). It'll still work, but for
cleanliness, it's a recommendation.
When I run the function like so, it works without fail:
<?php
echo fMakeWideDate(date("m/d/Y"),1)."\n";
echo fMakeWideDate(date("m-d-Y"),1)."\n";
echo fMakeWideDate(date("Y/m/d"),2)."\n";
echo fMakeWideDate(date("Y.m.d"),2)."\n";
?>
Are you correctly passing the date? What do you see when you echo
out the MySQL rows?
--
</Daniel P. Brown>
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!
--- End Message ---
--- Begin Message ---
At 8:40 PM +0200 4/15/08, Zoltán Németh wrote:
tedd írta:
Hi gang:
Check out my new game:
http://webbytedd.com/quarters/
What do you think?
that's cool, the only problem is that I lost ten times out of ten ;)
maybe on the weekend I give it a deeper analysis
and so I can figure out the winning strategy -
because there must be one, which is used by the
program
greets,
Zoltán Németh
Zoltán:
There's a log story about that game. But briefly,
I was introduced to it by an old man in Bradford
Penn. I remember it cost me at least a case of
beer before I won a single game -- a very
deceptive game, at least it was to me.
But, the program follows a rule based AI
algorithm with a bit of randomness thrown in.
I've condensed winning down to three rules -- it
will be interesting to see if you can figure out
what those rules are. Of course, you could pay $5
and I'll email them to you. :-)
Seriously, I released the game for the Mac in
December 1999. In February, MacWorld ran it as
one of the top ten shareware games and my web
site had over 25,000 downloads that month and the
30+ shareware site out that had the game,
reported a total of over 200,000 downloads.
The original game asked for a self-addressed
stamped envelope with $5 in it and I would mail
the answer back. To my surprise, I received
hundreds of letters and money from all over the
world. Some of the currency would have cost me
more than $5 to cash at my local bank. That was
before PayPal did overseas transactions.
Some of the letters had photographs of the people
who wanted the secret. I specifically remember a
big biker from OZ who sent me a picture of
himself and his bike with a note that he was
going to make more than $5 by betting on the game
in bars. I'm sure he did.
It was a very interesting experience and I've
always wanted to put the game up on my site to
see what would happen. It's not for the money,
but rather the life experience.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
On Tue, Apr 15, 2008 at 5:17 PM, tedd <[EMAIL PROTECTED]> wrote:
>
> It was a very interesting experience and I've always wanted to put the game
> up on my site to see what would happen. It's not for the money, but rather
> the life experience.
That being the case, please update the PayPal link to [EMAIL PROTECTED]
Thank you for your cooperation.
--
</Daniel P. Brown>
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!
--- End Message ---
--- Begin Message ---
Dang it! You beat me to it!
Hey Tedd, Make it rotate between [EMAIL PROTECTED] and [EMAIL PROTECTED]
:-D
---- Daniel Brown <[EMAIL PROTECTED]> wrote:
> On Tue, Apr 15, 2008 at 5:17 PM, tedd <[EMAIL PROTECTED]> wrote:
> >
> > It was a very interesting experience and I've always wanted to put the game
> > up on my site to see what would happen. It's not for the money, but rather
> > the life experience.
>
> That being the case, please update the PayPal link to [EMAIL PROTECTED]
>
> Thank you for your cooperation.
>
> --
> </Daniel P. Brown>
> Ask me about:
> Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
> and shared hosting starting @ $2.50/mo.
> Unmanaged, managed, and fully-managed!
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
At 5:43 PM -0400 4/15/08, Wolf wrote:
Dang it! You beat me to it!
Hey Tedd, Make it rotate between [EMAIL PROTECTED] and [EMAIL PROTECTED]
You guys make me laugh.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
At 10:41 AM -0500 4/15/08, Steve Marquez wrote:
Greetings,
Can any of you point me in the right direction on how to use PHP to create a
most viewed or most clicked articles list? Can it be done with PHP?
Thank you so much,
Steve Marquez
[EMAIL PROTECTED]
Steve:
There are a couple of ways to do this: 1) use mysql to record each
download; 2) use a file to record each download.
All you do is pass the user's click to a php script that records the
transaction -- incrementing a counter in either mysql or a file and
delivers the content to the user. You can include that number in your
html to show how many transactions, if you want.
This is an example of using a file:
http://www.webbytedd.com/b/readwrite-download/
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
Daniel:
Your hosting service provides the capability to turn html text to
speech, as I've done here:
http://php1.net/b/speech/
We use php to generate a sound file and then we use javascript to
play it -- it all works great.
But, how do we delete the file? The php script is history after
presenting the page and javascript can't touch the server, right? So,
how does one delete the wave file?
The only way I can see is to set up a cron job to delete all wave
files after a certain time, but that's kind-of lame. Is there another
way?
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
On Tue, Apr 15, 2008 at 7:04 PM, tedd <[EMAIL PROTECTED]> wrote:
>
> Your hosting service provides the capability to turn html text to speech,
> as I've done here:
[snip!]
>
> But, how do we delete the file? The php script is history after presenting
> the page and javascript can't touch the server, right? So, how does one
> delete the wave file?
>
> The only way I can see is to set up a cron job to delete all wave files
> after a certain time, but that's kind-of lame. Is there another way?
Right, but unfortunately, because it's audio that needs to stream,
it can't just be served like an image (think GD or imagemagick) and
then destroyed. There is no way to know how long it will be before
the client receives the entire file, and it would prove to be too much
to store in a reasonable buffer.
That's why I had to write it the way it is. The drawback is that,
yes, unless you're overwriting the file each time (which, with
high-traffic sites, would corrupt larger files mid-download), you
either have to have a script to unlink() the files or a cron to remove
them (or resort to a manual removal).
I'm all ears, eyes, and cerebellum if you've got an idea on how to
fix that though. The next phase should have better speech, I'm just
having a tough time with paid gigs now and find no time to focus on
the fun stuff really. I still don't know why no one ever told us the
truth that, no matter how much we wanted to be Toys 'R' Us kids, the
answer was unscrupulously the same: tough nuts.
--
</Daniel P. Brown>
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!
--- End Message ---
--- Begin Message ---
Is there a way I can get my fsock to stay open when the child process
exits?
Kyle
--- End Message ---
--- Begin Message ---
You're trying to save an open socket connection that was gained by the
fork()'d process? I don't think that would be possible, since PHP closes
all the resources when the process ends. Unless there is some config option
to not do that.
Jason
On Tue, Apr 15, 2008 at 4:16 PM, Kyle Browning <[EMAIL PROTECTED]> wrote:
> Is there a way I can get my fsock to stay open when the child process
> exits?
>
> Kyle
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Hi,
Can anybody tell me how can php connect to NNTP to get the list of all users
in the newsgroups?
thanks,
--
View this message in context:
http://www.nabble.com/PHP-with-NNTP--tp16713817p16713817.html
Sent from the PHP - General mailing list archive at Nabble.com.
--- End Message ---
--- Begin Message ---
vester_s wrote:
>
> Hi,
>
> Can anybody tell me how can php connect to NNTP to get the list of all
> users in the newsgroups?
>
I'm not sure about getting "all the users", but you could create a
connection using plain socket programming. NNTP is a pretty simple
protocol.
/Per Jessen, Zürich
--- End Message ---
--- Begin Message ---
vester_s wrote:
Hi,
Can anybody tell me how can php connect to NNTP to get the list of all users
in the newsgroups?
http://php.net/imap supports nntp.
--
Postgresql & php tutorials
http://www.designmagick.com/
--- End Message ---
--- Begin Message ---
On Wednesday 16 April 2008, vester_s wrote:
> Can anybody tell me how can php connect to NNTP to get the list of all
> users in the newsgroups?
NNTP has no concept of "users".
--
Crayon
--- End Message ---
--- Begin Message ---
On Tuesday 15 April 2008, Daevid Vincent wrote:
> I've had at least three job interviews in the past two weeks, and each one
> has asked me this rather "text book academic" question regarding the
> difference between "abstract" vs. "interface". I've been coding for nearly
> 20 years, and at least 10 of those have been in PHP and another 3 in J++. I
> have NEVER used either of these concepts/keywords? Am I missing some
> exciting tool/feature?
>
> All the reading I've done tonight just reinforces my thoughts that these
> are, for the most part useless. Unless you're building some HUGE project
> that has an API and there are teams of people that are going to extend your
> framework, then what good are they?
You've just answered your own question, albeit in a rather naive way.
If your code doesn't have an API and clear separation of parts, then neither
abstract classes nor interfaces are useful to you.
If you're coding anything of respectable size, vis, more than a one-off 1000
line script or less, then you either want to have an API and clear separation
of parts or I don't want to hire you, because your code is going to be an
unmaintainable mess.
Abstract classes and interfaces are a standardized, syntactic way to establish
an API and clean separation of parts. They are not the only way to
accomplish that goal by any means, but they are a commonly understood way
that, if used properly, can create a very good API and very clean separation
of parts. If used stupidly, of course, you'll create a system that is
completely inflexible and impossible to extend. That comes down to the skill
and experience of the developer and architect.
If you're not writing OOP code, then neither is of any use to you as both are
OOP concepts. (And you don't have to write OOP code if it doesn't make
sense, but don't shun it either because often it does make sense.)
In general, an interface defines a "front end" of a class, without specifying
anything about its implementation. All component A needs to know about
component B is that it implements interface Foo, meaning that you know,
absolutely, that you can call $b->foo() and get back a string and $b->bar()
and get back a database connection, because the interface says so. (If
that's not the case, then B is buggy by definition.) You don't know or care
how it goes about getting that database connection (creates it, loads it from
a cache, creates a fake one for you, etc.), just that you can call $b->bar()
and get back a database connection. A class may implement any number of
interfaces.
An abstract class defines a "front end" *and* the implementation behind it,
modulo some bits. It is exactly the same as any other parent class, except
that it defines bits of functionality that it is missing that its child
classes *must* finish. That's useful if you have some number of classes that
are *almost* the same, but have no "generic" form. Database abstraction
systems are probably the canonical example here.
Usually, you will want to use an interface (possibly with composition) over an
abstract class unless you have a ton of shared code, as interfaces are more
flexible in a single-inheritance system.
Yes, you can get by just fine without them. You can also get by without OOP
at all. However, there are some problems where OOP just makes things a lot
easier, and in OOP there are places where having a formal interface just
makes things a lot easier; like, say, when you're reading someone else's code
and trying to make sense of what it's supposed to do and what assumptions are
being made. Having that built right into the syntax can be quite useful,
even in a loosely typed language like 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
--- End Message ---
--- Begin Message ---
ALarry Garfield wrote:
On Tuesday 15 April 2008, Daevid Vincent wrote:
I've had at least three job interviews in the past two weeks, and each one
has asked me this rather "text book academic" question regarding the
difference between "abstract" vs. "interface". I've been coding for nearly
20 years, and at least 10 of those have been in PHP and another 3 in J++. I
have NEVER used either of these concepts/keywords? Am I missing some
exciting tool/feature?
All the reading I've done tonight just reinforces my thoughts that these
are, for the most part useless. Unless you're building some HUGE project
that has an API and there are teams of people that are going to extend your
framework, then what good are they?
You've just answered your own question, albeit in a rather naive way.
If your code doesn't have an API and clear separation of parts, then neither
abstract classes nor interfaces are useful to you.
If you're coding anything of respectable size, vis, more than a one-off 1000
line script or less, then you either want to have an API and clear separation
of parts or I don't want to hire you, because your code is going to be an
unmaintainable mess.
Abstract classes and interfaces are a standardized, syntactic way to establish
an API and clean separation of parts. They are not the only way to
accomplish that goal by any means, but they are a commonly understood way
that, if used properly, can create a very good API and very clean separation
of parts. If used stupidly, of course, you'll create a system that is
completely inflexible and impossible to extend. That comes down to the skill
and experience of the developer and architect.
If you're not writing OOP code, then neither is of any use to you as both are
OOP concepts. (And you don't have to write OOP code if it doesn't make
sense, but don't shun it either because often it does make sense.)
In general, an interface defines a "front end" of a class, without specifying
anything about its implementation. All component A needs to know about
component B is that it implements interface Foo, meaning that you know,
absolutely, that you can call $b->foo() and get back a string and $b->bar()
and get back a database connection, because the interface says so. (If
that's not the case, then B is buggy by definition.) You don't know or care
how it goes about getting that database connection (creates it, loads it from
a cache, creates a fake one for you, etc.), just that you can call $b->bar()
and get back a database connection. A class may implement any number of
interfaces.
An abstract class defines a "front end" *and* the implementation behind it,
modulo some bits. It is exactly the same as any other parent class, except
that it defines bits of functionality that it is missing that its child
classes *must* finish. That's useful if you have some number of classes that
are *almost* the same, but have no "generic" form. Database abstraction
systems are probably the canonical example here.
Usually, you will want to use an interface (possibly with composition) over an
abstract class unless you have a ton of shared code, as interfaces are more
flexible in a single-inheritance system.
Yes, you can get by just fine without them. You can also get by without OOP
at all. However, there are some problems where OOP just makes things a lot
easier, and in OOP there are places where having a formal interface just
makes things a lot easier; like, say, when you're reading someone else's code
and trying to make sense of what it's supposed to do and what assumptions are
being made. Having that built right into the syntax can be quite useful,
even in a loosely typed language like PHP.
And, I believe that you can't instantiate abstract classes, they can
only be inherited.
-Shawn
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Larry Garfield [mailto:[EMAIL PROTECTED]
>
> If your code doesn't have an API and clear separation of
> parts, then neither
> abstract classes nor interfaces are useful to you.
>
> If you're coding anything of respectable size, vis, more than
> a one-off 1000
> line script or less, then you either want to have an API and
> clear separation
> of parts or I don't want to hire you, because your code is
> going to be an unmaintainable mess.
That is soooo not true. My last company had nearly 15 developers and we never
used either of these concepts in the six years the company existed. We had
perhaps 50+ classes and some had upwards of 5-KLOC each. We had three databases
with almost 300 tables. We had an external XML API that hooked into these
classes with 'set', 'get', 'add', 'delete' and all the commands you would
expect. And we weren't doing simple stuff either. This was an extremely complex
appliance that was HEAVILY PHP/Ruby driven (http://www.lockdownnetworks.com).
I'm not trying to start a war here, I just really don't see how any PHP project
other than the very fringe examples such as a DB abstraction project or huge
PEAR project has any _real_ need for this. Sure, it's all text-book and
"proper" perhaps, but to me it just seems like bloat and if you intend to
extend a given class, you STILL have to read the source code and examine the
abstract class or interface anyways to know what you have to implement in your
derived class (right?)
90% of the LAMP projects amount to some website/service, some user
registration, some blogs or threaded discussion, some database entries. They're
really not all that complex in the big picture.
I can sort of see the use for these if you were designing an operating system
or a device driver or something HUGE. But come on -- a website is really not
that big (code wise). It may have thousands of pages, but they're built from a
relatively small amount of dynamic PHP pages.
In any event, thanks for your detailed reply Larry. I get the concepts. I just
don't see the general-use-case need in PHP's OOP world. Maybe sometime the
light-switch will flip on for me and I'll realize I've been skating uphill all
these years...
Daevid.
P.S. you should look at my resume before you decide not to hire me ;-p
http://resume.daevid.com
--- End Message ---
--- Begin Message ---
On Wednesday 16 April 2008, Daevid Vincent wrote:
> > -----Original Message-----
> > From: Larry Garfield [mailto:[EMAIL PROTECTED]
> >
> > If your code doesn't have an API and clear separation of
> > parts, then neither
> > abstract classes nor interfaces are useful to you.
> >
> > If you're coding anything of respectable size, vis, more than
> > a one-off 1000
> > line script or less, then you either want to have an API and
> > clear separation
> > of parts or I don't want to hire you, because your code is
> > going to be an unmaintainable mess.
>
> That is soooo not true. My last company had nearly 15 developers and we
> never used either of these concepts in the six years the company existed.
> We had perhaps 50+ classes and some had upwards of 5-KLOC each. We had
> three databases with almost 300 tables. We had an external XML API that
> hooked into these classes with 'set', 'get', 'add', 'delete' and all the
> commands you would expect. And we weren't doing simple stuff either. This
> was an extremely complex appliance that was HEAVILY PHP/Ruby driven
> (http://www.lockdownnetworks.com).
>
> I'm not trying to start a war here, I just really don't see how any PHP
> project other than the very fringe examples such as a DB abstraction
> project or huge PEAR project has any _real_ need for this. Sure, it's all
> text-book and "proper" perhaps, but to me it just seems like bloat and if
> you intend to extend a given class, you STILL have to read the source code
> and examine the abstract class or interface anyways to know what you have
> to implement in your derived class (right?)
>
> 90% of the LAMP projects amount to some website/service, some user
> registration, some blogs or threaded discussion, some database entries.
> They're really not all that complex in the big picture.
>
> I can sort of see the use for these if you were designing an operating
> system or a device driver or something HUGE. But come on -- a website is
> really not that big (code wise). It may have thousands of pages, but
> they're built from a relatively small amount of dynamic PHP pages.
>
> In any event, thanks for your detailed reply Larry. I get the concepts. I
> just don't see the general-use-case need in PHP's OOP world. Maybe sometime
> the light-switch will flip on for me and I'll realize I've been skating
> uphill all these years...
>
> Daevid.
>
> P.S. you should look at my resume before you decide not to hire me ;-p
> http://resume.daevid.com
Please take note of what I said. I did not say "if you're coding anything of
respectable size without interfaces and abstract classes, I don't want to
hire you." I said "If you're coding anything of respectable size clean
separation of parts and an API between them, I don't want to hire you."
Interfaces, abstract classes, and the rest of OOP are *A* way of defining an
API and separation of parts. It is not the only way. OOP is a tool, and
sometimes it's the right tool and sometimes it's not. Yes, it's overkill for
many small projects, but that doesn't make it never-useful.
I'm a Drupal developer. Our codebase is huge, and our contrib codebase is
over a million lines of code, I think. There's maybe 4 classes total in all
of that, all of them very recently added. :-) And yet the system itself is
extremely modular with clear APIs. It's the "modular and clear APIs" part
that makes it good, not the number of classes it has (or doesn't have).
Besides, interfaces and abstract classes only came to PHP in PHP 5. :-)
Now, that said, a 5000-line class? Unless 4500 lines of that is comments, I
have to question if you're understanding OO design properly. :-)
--
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
--- End Message ---