Classes Flashcards
What function is used to retrieve all defined functions in an array?
get_defined_function(void);
Returns array of all functions
What function is used to get class methods names?
get_class_method(mixed $class_name)
How do you check existence of method?
Use an method_exists(, ). Returns Boolean result
What function is used to retrieve list of declared classes names ?
Use get_declared_classes()
What is the difference between interface constants and class constants?
Interface constants can not be overridden by child unlike class constants.
What function can you use to check if a class exists?
Use class_exists(), Which returns Boolean
How can you call a class automatically which has not previously been defined?
Use _autoload() function
What function would you use to get array of given properties for an object?
Use get_objects_vars()
How do you iterate through list of items in an object?
Use foreach foreach( $class as $ key => $value) { print "$key => $value\n"; } By default, all visible properties will be used for the iteration.
What is overloading in php?
Overloading: Overloading in PHP provides means to dynamically “create” properties and methods. These dynamic entities are processed via magic methods one can establish in a class for various action types.
The overloading methods are invoked when interacting with properties or methods that have not been declared or are not visible in the current scope. The rest of this section will use the terms “inaccessible properties” and “inaccessible methods” to refer to this combination of declaration and visibility.
All overloading methods must be defined as public.
How do you return a reference from a function?
To return a reference from a function, use the reference operator & in both the function declaration and when assigning the returned value to a variable:
What is the use of the keyword “self” ?
It is used as means of class referencing its static properties
What method is used to get defined classes ?
Use get_declared_class(); Which returns an array of declared class names in current script.