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

Similar things

  • Emulating closures in PHP
  • Some ways to use saved state with closures in php
  • Scoped php functions or more ways to abuse php
  • Going mad talking about relations
  • Relations and their domain structures
  • Once again relations, or the need to focus on smaller parts of the big picture. A rant.
  • Learning lessons from Lisp or patterns and languages in PHP
  • LISP-like programming in php
  • Does Visual Studio Rot the Mind?
  • Overcomplicated design pattern implementations

Home » blogs » vlado's blog

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

vlado's blog | add new comment
Home » blogs » vlado's blog

dikini.net

spreading confusion by accident since 1970