Chapter 5 - PHP Functions and Objects Flashcards
What are five benefits of using functions instead of contiguous, inline code?
- Involve less typing
- Reduce syntax and other programming errors
- Decrease the loading time of program files
- Decrease execution time, because each function is compiled only once, no matter how often you call it
- Accept arguments and can therefore be used for general as well as specific cases
What does the ‘include’ statement do?
Using include, we can tell PHP to fetch a particular file and load all its contents. It’s as if you pasted the included file into the current file at the insertion point.
What does the include_once statement do?
Each time you issue the include directive, it includes the requested file again, even if you’ve already inserted it. For instance, suppose that library.php contains a lot of useful functions, so you include it in your file, but also include another library that includes library.php. Through nesting, you’ve included library.php twice, by mistake.
What does the include_once statement do?
Each time you issue the include directive, it includes the requested file again, even if you’ve already inserted it. For instance, suppose that library.php contains a lot of useful functions, so you include it in your file, but also include another library that includes library.php. Through nesting, you’ve included library.php twice, by mistake.
What are require and require_once used for?
A potential problem with include and include_once is that PHP will only attempt to include the requested file. Program execution continues even if the file is not found.
When the file is essential to the program, it should be ‘required’. If the document is not fund, it will not run and will abort.
What are require and require_once used for?
A potential problem with include and include_once is that PHP will only attempt to include the requested file. Program execution continues even if the file is not found.
When the file is essential to the program, it should be ‘required’. If the document is not fund, it will not run and will abort.
How do you ensure PHP version compatibility?
PHP is an ongoing process of development, and there are multiple versions. If you need to check whether a particular function is available to your code, you can use the function_exists function, which checks all predefined and user-created functions.
In terms of objects, what is a class?
When creating a program to use objects, you need to design a composite of data and code called a class.
In terms of an object, what is an instance or occurrence of a class?
Each new object based on a class is called an instance.
In terms of an object, what is an instance or occurrence of a class?
Each new object based on a class is called an instance.
What are properties?
The data associated with an object.
What are the functions used by an object?
Methods
Give a example of declaring a class:
How do you create an object?
$object = new User; $temp = new User(‘name’, ‘password’);
What is a constructor?
When creating a new object, you can pass a list of arguments to the class being called. These are passed to a special method within the class, called the constructor, which initializes various properties.