Skip to content

Instantly share code, notes, and snippets.

@Mordo95
Last active March 1, 2018 16:08
Show Gist options
  • Save Mordo95/c7b041a1af5fe17b032d3008fd0303fa to your computer and use it in GitHub Desktop.
Save Mordo95/c7b041a1af5fe17b032d3008fd0303fa to your computer and use it in GitHub Desktop.
A function to check if the call was internal, since PHP does not have the internal access modifier.
<?php
abstract class Internal {
protected function checkInternalCall() {
$bt = debug_backtrace();
if (count($bt) < 2 || !isset($bt[1]['class']) || substr($bt[1]['class'], 0, strlen(__NAMESPACE__) + 1) != __NAMESPACE__ . "\\")
throw new \Exception("This function is marked as 'internal' and cannot be called outside of the namespace");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment