1

can I use this syntax under PHP 4 (default function parameter) :

function myFunction($arg1 = 'defaultValue') {}

Thanks.

2
  • if it is a question, the answer is yes. Commented Sep 28, 2010 at 9:13
  • Actually, I would very much encourage use of default parameters in every function. Commented Sep 28, 2010 at 9:18

3 Answers 3

4

Yes you can. And it can be overwritten like this:

<?php
$var = 'one';
myFunction($var);

function myFunction($arg1 = 'defaultValue') {
echo $arg1;
}
?>

the output would be one

Sign up to request clarification or add additional context in comments.

Comments

1

Yes you definitely can do.

Hope it helps.

Comments

1

why don't you simply try it? yes, you can.

1 Comment

I use php 5 on my dev machine but I want my code to be compatible with php 4 too...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.