For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > May 2007 > Re: To OOP or not to OOP









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: To OOP or not to OOP
L. Berger

2007-05-30, 7:00 pm

On May 30, 11:46 pm, "Gregor" <rmba...@comcast.net> wrote:
> "L. Berger" <straightfwd...@gmail.com> wrote in message
>
> news:1180451838.251123.37150@d30g2000prg.googlegroups.com...
> * * *
>
>
> * * *
>
> Could you explain these for me please, if you have the time?
>
> I can understand the obvious reasons to minimize require calls, but why do
> you prefer, say, "require()" over "require_once()"? And why not use
> "include()" for, say, a block of stand-alone text when you would rather see
> it omitted than have the page not load?



Sorry, it was not very clever of me to make a pronouncement without
explanation. First, let's compare include and require, two
differences:

1. Include will only include the file when conditionally appropriate,
require will simply include it. In reality, especially when using an
accelerator (more about that below), require simply becomes a part of
your code. This is better than the PHP executable having to do some
additional processing to figure out whether something was necessary to
include or not. It's always there. When it is converted to bytecode,
it's there.

2. Include throws warnings, require throws errors -- which is an
important consideration for production level code. An application that
I had worked on (during corporate years) used "includes" of pretty
important functionality that went into transactions. Because this was
production server, the "error_reporting" was set to "E_ALL ^ E_NOTICE
^ E_WARNING". When includes failed, the warnings were not thrown out,
the transaction went incomplete but done. In cases like these
"require" is quite important ("includes" with checking for file
existence would have been much slower).

So yes, it depends on your particular situation and what your
application does (for small apps either is fine) but require has
turned out to be more effective for me.



> I have never heard of an accelerator. I'm assuming it acts a bit like a css
> optimizer, perhaps sort of a poor man's framework? Does eAccelerator ever
> create bugs, like css optimization programs?



Google is your friend :) eAccelerator is the latest version of an
older caching solution, memturk. It's turned out much better for me
than APC especially when . Basically, these products compile your PHP
code into byte code, then store it in memory. As far as I know,
eAccelerator does not break any functionality and is highly tested by
the OSS community. There's a good explanation (and some thoroughly
unscientific testing) at these sites:

http://www.ipersec.com/index.php?q=en/bench_ea_vs_apc or
http://www.mysqlperformanceblog.com...nce-comparison/
-- which show that eAccelerator


Schraalhans Keukenmeester

2007-05-31, 7:00 pm

At Wed, 30 May 2007 10:55:52 -0700, L. Berger let h(is|er) monkeys type:

> On May 30, 11:46 pm, "Gregor" <rmba...@comcast.net> wrote:
>
>
> Sorry, it was not very clever of me to make a pronouncement without
> explanation. First, let's compare include and require, two
> differences:
>
> 1. Include will only include the file when conditionally appropriate,
> require will simply include it. In reality, especially when using an
> accelerator (more about that below), require simply becomes a part of
> your code. This is better than the PHP executable having to do some
> additional processing to figure out whether something was necessary to
> include or not. It's always there. When it is converted to bytecode,
> it's there.
>


Nonsense. Include and Require Both do as told unconditionally. You are
mistaken. Check it, try including a php class or func definition file
twice.
Conditional inclusion/requirement is happens with include_once
and require_once.

> 2. Include throws warnings, require throws errors -- which is an
> important consideration for production level code.


Yes, it is. I think no production code ought to spit out errors or
warnings which haven't been handled by the programmer. Do your own error
checking, use try/catch blocks, don't let PHP simply spew out default
errors. Which renders your second point moot as well imho.

Rgds
--
Schraalhans Keukenmeester - schraalhans@the.spamtrapexample.nl
[Remove the lowercase part of Spamtrap to send me a message]

"strcmp('apples','oranges') < 0"

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com