Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

getTraceAsString()

Example

Display the stack trace.

<?php
function myFunction($num) {
  throw new Exception(“An error occurred”);
}

try {
  myFunction(5);
catch (Exception $e) {
  print_r($e->getTraceAsString());
}
?>

Definition and Usage

The getTraceAsString() method returns the stack trace as a string.

 

Stack traces provide details about all the functions executing at a specific moment. This method’s stack trace reflects the state of the stack when the exception was thrown.

Syntax

$exception->getTraceAsString()

Technical Details

Return Value:

Returns the stack trace as a string.