|
Clean my plate, but keep my wine bottle. (PHP; Static)
On Monday morning, I served Colin's breakfast on a clean plate in the "Whitworth" ... one happy camper, judging by the crumbs and butter wrappers left on the plate, and the smile on Colin's face.
Never wanting to disturb a customer's property and space, I carefully preserved the plate as Colin left it on that morning and returned the plate to him, in that same crumby condition, on Tuesday morning. But Colin didn't appreciate the care I had taken to preserve his crumbs and would have much preferred a clean start.
On Wednesday, I'll make sure he has a clean, pristine new plate!
When you call a function in PHP, the internal variables within that function are freshly re-initialised each time. There is no debris left over from previous operations. And that's a good and sensible default - just like Colin on Tuesday and Wednesday morning, you don't want to be reminded about what happened on Monday.
Colin drank a glass of wine out of a bottle he brought with him on Tuesday night, and came looking for it to have another glass on Wednesday night. He was a little unhappy that we had cleaned up and thrown out his undrunk wine, even though he had requested a clean breakfast plate each morning. This is an exception to the "clean up fully every time" rule ... and in PHP terms, you would declare a variable within the function to be static to ensure that its value is held from one call to the next. (written 2007-09-18 11:21:35)
Associated topics are indexed under H105 - PHP - Functions
Some other Articles
Korn shell courseAsda in Melksham - Welcome or not?Little Gems but not LettuceLook forward with a new broom - Wiltshire Train ServiceClean my plate, but keep my wine bottle. (PHP; Static)Crystal Ball - How long do I need to be online?.php or .html extension? Morally Static PagesMatch the Bedroom to the HotelMood shotsActionscript / Flash / Flex (IAQ/FAQ)
|
2259 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46 at 50 posts per page
This is a page archived from The Horse's Mouth at
http://www.wellho.net/horse/ -
the diary and writings of Graham Ellis.
Every attempt was made to provide current information at the time the
page was written, but things do move forward in our business - new software
releases, price changes, new techniques. Please check back via
our main site for current courses,
prices, versions, etc - any mention of a price in "The Horse's Mouth"
cannot be taken as an offer to supply at that price.
Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).
|
|