Use Named Callback Functions for Auditability
Replaces inline callback behavior with named callback functions so the transformation is searchable and auditable.
Purpose
Replaces inline callback behavior with named callback functions so the transformation is searchable and auditable.
Snippet details
ContextCallbackLevelProductionCopy-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.
*/
/**
* Formats a callsign with an auditable named callback.
*
* @param string $callsign Raw callsign.
* @return string Formatted callsign.
*/
function ogSnippetNamedCallbackFormatCallsign(string $callsign): string {
$callsign = strtoupper(trim($callsign));
$callsign = str_replace(' ', '-', $callsign);
return $callsign;
}
/**
* Use Named Callback Functions for Auditability.
*
* Purpose:
* Uses a named callback instead of inline callback code.
*
* @param array $callsigns Raw callsigns.
* @return array Formatted callsigns.
*/
function ogSnippetUseNamedCallbackFunctionsForAuditability(array $callsigns): array {
$clean_callsigns = array();
foreach ($callsigns as $callsign) {
if (is_scalar($callsign) === true) {
$clean_callsigns[] = (string) $callsign;
}
}
return array_map('ogSnippetNamedCallbackFormatCallsign', $clean_callsigns);
}
$callsigns = ogSnippetUseNamedCallbackFunctionsForAuditability(array('red five', 'gold leader'));
echo 'Named callback callsign: '.$callsigns[0];