Skip to content

Instantly share code, notes, and snippets.

@pdewouters
Last active December 22, 2015 23:59
Show Gist options
  • Select an option

  • Save pdewouters/6550083 to your computer and use it in GitHub Desktop.

Select an option

Save pdewouters/6550083 to your computer and use it in GitHub Desktop.
If you don't define the custom error handler, the application with fatal error: `PHP Catchable fatal error: Argument 1 passed to Arr_Test::__construct() must be of the type array, string given`
<?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";
}
}
}
try {
$my_string_var = 'I am a string';
$myObj1 = new Arr_Test( $my_string_var );
} catch (Exception $e) {
echo $e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment