Last active
March 1, 2018 16:08
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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