terminal-auspicious

Topics

programming

php drupal scheme scheming macros design patterns da la

design

design css

random thoughts

scribbles

alter ego

other me 'em that link us my space me linked in

Collections

Programmable web
PHP design patterns

out of the (php) loop

Submitted by vlado on Wed, 2006-08-09 16:32.php | programming | scribbles

inspired by Verity , my urge to display my writing talent and random buzz on the internet

This conversation was (allegedly) overheard in a nursery, which won't be disclosed to avoid litigation

Write a standard php loop on the nursery blackboard

Come on, can't be bothered. Are you joking?
foreach( $array as $key => $value ) echo "$key $value";

Wrong! Don't you ever learn proper language usage

What have I done NOW?

Firstly, you should use ArrayObject from SPL and an iterator. That is the right way now. It is more extendable and proper OOP. You'll be able to apply various design patterns then. It gets really neater.

Yeah right. All I want to do is print the bloody thing. It's easier and faster the way I've done it.

Code like yours is not maintainable or enterprise ready. Really - you should plan for the future.

But you asked me to do a loop

What if you want to loop over a different container and not a simple array? Arrays are not even objects

Then I'll write another

And if you want to do the same for ten other things?

If need arises I'll wrap it in a switch or something else. Really, it depends on the case, I think.

You should think in perspective. Design properly.

But why do you have foreach in the language? And while, and the rest of the gang?

They are still there for compatibility reasons.

Really?

It looks like it

I'm really sorry, but don't have the record of the rest of the conversation

read more | vlado's blog | add new comment

Reply

Please solve the math problem above and type in the result. e.g. for 1+1, type 2
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <br /> <br> <div> <a> <em> <strong> <cite> <pre> <code> <ul> <ol> <li> <dl> <dt> <dd> <h3> <img> <blockquote> <q> <strike> <small> <h4> <h5> <h6>
  • Link to content with [[some text]], where "some text" is the title of existing content or the title of a new piece of content to create. You can also link text to a different title by using [[link to this title|show this text]]. Link to outside URLs with [[http://www.example.com|some text]], or even [[http://www.example.com]].
  • Lines and paragraphs break automatically.
More information about formatting options
Home ยป out of the (php) loop

dikini.net

spreading confusion by accident since 1970