Page 4 of 4
Posted: Mon Jun 04, 2007 7:12 pm
by superdezign
Jenk wrote:lest not forget func_get_args() etc. too.
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.

Posted: Mon Jun 04, 2007 7:21 pm
by Christopher
Jenk wrote:lest not forget func_get_args() etc. too.
Oh yeah, and that's only the start of it. You can forget things like
function foo (int bar) and
function foo (float bar) as well.
Posted: Mon Jun 04, 2007 7:36 pm
by RobertGonzalez
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."
PHP 5 For Dummies wrote:Using empty brackets:
Code: Select all
$colors[] = "red";
$colors[] = "blue";
Result:
Code: Select all
$colors[1] = "red";
$colors[2] = "blue";
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.
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.
Posted: Mon Jun 04, 2007 7:43 pm
by superdezign
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?)
Posted: Mon Jun 04, 2007 9:15 pm
by feyd
Yes, arrays are zero based.
Posted: Tue Jun 05, 2007 2:38 am
by abalfazl
Hello!
When using of duck typing is better ?In which case do you suggest it?
Posted: Tue Jun 05, 2007 6:55 am
by feyd
Variable naming is entirely personal choice. There's no "best."
Posted: Tue Jun 05, 2007 11:34 am
by Christopher
abalfazl wrote:When using of duck typing is better ?In which case do you suggest it?
Yes. Duck typing is a natural way to solve some problems in PHP.
Posted: Wed Jun 06, 2007 12:00 am
by abalfazl
Hello!
I want to know when using of duck typing is better than using of inheritance or interface in order to polymorphism?
Posted: Wed Jun 06, 2007 12:27 am
by Christopher
abalfazl wrote:I want to know when using of duck typing is better than using of inheritance or interface in order to polymorphism?
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.
Posted: Fri Jun 08, 2007 4:38 am
by abalfazl
Hello!
What is your idea about this:
Interfaces have two uses; To allow duck typing in static languages, and to carry meta information about a class. The former is irrelevant in PHP.
Agree?
Posted: Fri Jun 08, 2007 8:00 am
by superdezign
... Kind of what arborint just said....