Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Object-Oriented PHP Basics Building the Recipe Ready Get Set Go

Sujal Khatiwada
PLUS
Sujal Khatiwada
Courses Plus Student 204 Points

To allow a method to accept an OPTIONAL argument, what do we need to do?

To allow a method to accept an OPTIONAL argument, what do we need to do?

2 Answers

David Evans
David Evans
10,490 Points

Hi Sujal.

To allow a method to accept an optional argument, simply set a default.

The correct answer for the quiz is: Set the method parameter equal to a default value.

An example would be:

<?php
public function setMemberID($id = 0) {
// method/function code here
}
?>```

Simple Set the variable value to 0 or null.