Created
September 13, 2013 12:36
-
-
Save pdewouters/6550105 to your computer and use it in GitHub Desktop.
If you don't use a try...catch block, and no error handler it's the same as no error handler with the try...catch blocks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Class Arr_Test | |
| */ | |
| class Arr_Test { | |
| /** | |
| * Gives us a property to play with | |
| * @var array | |
| */ | |
| var $objArr = array(); | |
| /** | |
| * Our object constructor | |
| * @param array $myArr | |
| */ | |
| public function __construct( array $myArr = array() ) { | |
| // Initialize our property to the value of the passed param | |
| $this->objArr = $myArr; | |
| // call a method to test this code | |
| $this->print_myarr(); | |
| } | |
| /** | |
| * Simply iterates an array | |
| */ | |
| protected function print_myarr(){ | |
| if ( is_array( $this->objArr ) ) { | |
| if ( count( $this->objArr ) > 0 ) { | |
| for ( $i=0; $i < count( $this->objArr ); $i++) { | |
| echo $this->objArr[$i]; // this would fail if our property is not an array | |
| } | |
| } else { | |
| echo "objArr is empty"; | |
| } | |
| } else { | |
| echo "not an array"; | |
| } | |
| } | |
| } | |
| $my_string_var = 'I am a string'; | |
| $myObj1 = new Arr_Test( $my_string_var ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment