Magic Constants
Returns common PHP magic constants from inside a function so their file, directory, line, and function values are visible.
Purpose
Returns common PHP magic constants from inside a function so their file, directory, line, and function values are visible.
Snippet details
ContextLanguageLevelProductionCopy-and-paste statusMarked safe after review.Categories
- Forms and Validation
Code
<?php
/*
* Copyright (c) 2026 Jeffery L. Paris <jparis@phpog.com>.
* Free for personal and internal use. Paid project use requires visible credit
* to Jeffery L. Paris. Corporate use requires a paid license fee unless a
* separate written license states otherwise.
*/
/**
* Magic Constants.
*
* Purpose:
* Returns common PHP magic constant values from this file and function.
*
* @return array Magic constant report.
*/
function ogSnippetMagicConstants(): array {
return array(
'file' => __FILE__,
'directory' => __DIR__,
'function' => __FUNCTION__,
'line' => __LINE__
);
}
$magic_report = ogSnippetMagicConstants();
echo 'Magic function: '.$magic_report['function'];