ch5 questions Flashcards

1
Q

What is the main benefit of using a function?

A

Less typing, reduced syntax and other programming errors, decreased loading time of program files. Decreased execution time, because each function is compiled only once no matter how often you call it.
Accepts arguments and can therefor be used for general as well as specific cases

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How many values can a function return?

A

By default, a function can return a single value. But by utilizing arrays, references, and global variables, any number of values can be returned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the difference between accessing a variable by name and by reference?

A

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 single value is referenced by more than one name. Changing the value of the reference will change the original as well.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the meaning of scope in PHP?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can you incorporate one PHP file with another?

A

Using include or require directives, or their safer varients, include_once and require_once.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How is an object different from a function?

A

A function is a set of statements referenced by a name that can receive and return values. An object may contain zero or as many functions (which are then called methods) as well as variables (which are called properties), all combined in a single unit.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you create a new object in PHP?

A

$object = new Class;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What syntax would you use to create a subclass from an existing one?

A

using the extends keyword
ex:
class Subclass extends Parentclass

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How can you call an initializing piece of code when an object is created?

A

To call a piece of initializing code when an object is created, create a constructor method called __construct within the class and place your code there.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why is it a good idea to explicitly declare properties within a class?

A

Explicitly declaring properties within a class is unnecessary, as they will be implicitly declared upon first use. But it is considered good practice as it helps with code readability and debugging, and is especially useful to other people who may have to maintain your code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly