THAT'S the function I've been looking for! I thought it'd be fun to program an SQL query function similar to printf(), and have it automatically escape variables.Jenk wrote:lest not forget func_get_args() etc. too.
Polymorphism
Moderator: General Moderators
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Yes, PHP arrays are zero-based. So I would suspect that is a type unless somewhere in there there was another array member before that which had a 0 index assigned to it.superdezign wrote:And, out of curiosity, is this a typo? I opened the book and it's the first thing that I read on the "cheat sheet" and I just thought to myself, "Either I'm wrong, or this book may not have been the best choice."
I could have sworn that this code would start the array off at the zero index, but when I think about it, I've grown used to using the foreach loop, so I've never checked.PHP 5 For Dummies wrote:Using empty brackets:Result:Code: Select all
$colors[] = "red"; $colors[] = "blue";Code: Select all
$colors[1] = "red"; $colors[2] = "blue";
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Thought so! What a wonderful way to introduce me to the book.... And at no point in the cheat sheet does it mention that the first index of an array is zero.
Eh. What can you do. It's already published. :-p
(Strangely, it has nearly the SAME little comics between chapters as a different web-development related "For Dummies" book that I read/skimmed. Fresh out of jokes?)
Eh. What can you do. It's already published. :-p
(Strangely, it has nearly the SAME little comics between chapters as a different web-development related "For Dummies" book that I read/skimmed. Fresh out of jokes?)
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
In PHP it does not matter. The reason that people discuss inheritance is because in other languages you can only do polymorphism by inheritance. PHP does not have that constraint. You can use a class polymorphically that either inherits method foo() or creates its own foo() method. Neither is better.abalfazl wrote:I want to know when using of duck typing is better than using of inheritance or interface in order to polymorphism?
(#10850)
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm