PHP error_get_last() Function Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report The error_get_last() function is an inbuilt PHP function in PHP which is used to get the last error that occurred. Syntax: error_get_last(): ?arrayParameter: This function does not accept any parameters. Return Value: It returns an associate array that explains the last error with keys "type", "message", "file" and "line", which will be returned. The "message" will begin with its name, if the error occurred by PHP internal function, otherwise, return null for not finding any error yet. Example 1: The following code demonstrates the error_get_last() function. PHP <?php $file = 'filedoesnotexist.txt'; $handle = fopen($file, 'r'); if ($handle === false) { $error = error_get_last(); echo "Error opening file: " . $error['message']; } else { // Do something with the file handle fclose($handle); } ?> Output: Error opening file: fopen(filedoesnotexist.txt): Failed to open stream: No such file or directory Example 2: The following code demonstrates the error_get_last() function. PHP <?php $a = 10 ; if(error_get_last()) { echo "This never will print because no error " ; } else { echo "No error occurs, so it will return null"; } ?> Output: No error occurs, so it will return null Reference: https://www.php.net/manual/en/function.error-get-last.php Comment More infoAdvertise with us Next Article PHP error_get_last() Function neeraj3304 Follow Improve Article Tags : PHP PHP-function PHP-Error-Handling Similar Reads PHP | date_get_last_errors() Function The date_get_last_errors() function is an inbuilt function in PHP which is used to returns the warnings and errors. This function parse a date/time string and returns an array of warnings and errors. Syntax: Procedural style: array date_get_last_errors( void ) Object oriented style: array DateTime:: 1 min read PHP error_clear_last() Function The error_clear_last() function is an inbuilt function in PHP that is utilized to remove the most recent error. Syntax: error_clear_last(): void Parameter: This function does not accept any parameters. Return Value: The most recent error will be cleared & making it impossible to retrieve that er 1 min read PHP array_âkey_âlast() Function The array_âkey_âlast() function is an inbuilt function in PHP that is used to get the last key of an array. This function returns the last key without affecting the internal array pointer. Syntax: int|string|null array_âkey_âlast(array $array) Parameters: This function accepts single parameter $arra 1 min read PHP | DsVector last() Function The Ds\Vector::last() function is an inbuilt function in PHP which is used to return the last element of the vector. Syntax: mixed public Ds\Vector::last( void ) Parameters: This function does not contain any parameter. Return Value: This function returns the value at the last index in the vector. B 1 min read PHP | getdate() Function The getdate() function is an inbuilt function in PHP which is used to get date/time information of the current local date/time. Syntax: getdate($timestamp) Parameters: The getdate() function accepts one parameter and it is described below: $timestamp: It is an optional parameter which specifies an i 2 min read PHP | DsSet last() Function The Ds\Set::last() function is an inbuilt function in PHP which is used to return the last element from the Set instance. Syntax: void public Ds\Set::last( void ) Parameter: This function does not accept any parameter. Return Value: This function returns the last value of the Set. Below programs ill 1 min read PHP | date_offset_get() Function The date_offset_get() function is an inbuilt function in PHP which is used to returns the timezone offset. This function returns the timezone offset in seconds from UTC (Universal Time Coordinated) on success or FALSE on failure. Syntax: Procedural Style: int date_offset_get( $object ) Object Orient 1 min read PHP | DsDeque last() Function The Ds\Deque::last() function is an inbuilt function in PHP which is used to return the last element of Deque if Deque is not empty. Syntax: public Ds\Deque::last( void ) : mixed Parameters: This function does not accept any parameter. Return Value: This function returns the last element in the dequ 2 min read PHP | DirectoryIterator getATime() Function The DirectoryIterator::getATime() function is an inbuilt function in PHP which is used to get the last access time of the current DirectoryIterator item. Syntax: int DirectoryIterator::getATime( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the 2 min read PHP | DatePeriod getEndDate() Function The DatePeriod::getEndDate() function is an inbuilt function in PHP which is used to return the end date. If the given date period does not have any end date then it returns NULL.Syntax: DateTimeInterface DatePeriod::getEndDate( void ) Parameters: This function does not accept any parameters. Return 1 min read Like