Chapter 5 Answers
Using functions avoids the need to copy or rewrite similar code sections many times over by combining sets of statements together so that they can be called by a simple name.
By default, a function can return a single value. But by utilizing arrays, references, and global variables, any number of values can be returned.
When you reference a variable by name, such as by assigning its value to another variable or by passing its value to a function, its value is copied. The original does not change when the copy is changed. But if you reference a variable, only a pointer (or reference) to its value is used, so that a single value is referenced by more than one name. Changing the value of the reference will change the original as well.
Scope refers to which parts of a program can access a variable. For example, a variable of global scope can be accessed by all parts of a PHP program.
To incorporate one file within another, you can use the
includeorrequiredirectives, or their safer variants,include_onceandrequire_once.A function is a set of statements referenced by a name that can receive and return values. An object may contain zero, one, or many functions (which are then called methods) as well as variables (which are called properties), all combined in a single unit.
To create a new object in PHP, use the
newkeyword like this:$object = new Class.To create a subclass, use the
extendskeyword with syntax such as this:class Subclass extends Parentclass.To call a ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access