Skip to content

Instantly share code, notes, and snippets.

@thekid
Created March 23, 2012 08:27
Show Gist options
  • Select an option

  • Save thekid/2168311 to your computer and use it in GitHub Desktop.

Select an option

Save thekid/2168311 to your computer and use it in GitHub Desktop.
ThrowableSecurityExtensions - alternative to pull request #136
<?php
/* This class is part of the XP framework
*
* $Id$
*/
/**
* Throwable extension methods
*
* @see https://github.com/xp-framework/xp-framework/pull/136
*/
class ThrowableSecurityExtensions extends Object {
static function __import($scope) {
xp::extensions(__CLASS__, $scope);
}
/**
* Clears stacktrace
*
* @param lang.Throwable self
*/
public static function clearStackTraceArguments(Throwable $self) {
foreach ($self->getStackTrace() as $element) {
$element->args= array(sizeof($element->args).' arg(s)');
}
}
}
?>
<?php
/* This class is part of the XP framework
*
* $Id$
*/
uses('issue136.ThrowableSecurityExtensions');
/**
* Demonstrates ThrowableSecurityExtensions
*
*/
class ThrowableTest extends Object {
/**
* Throws an exception
*
* @param var info1
*/
protected static function calledWithSensitiveInformation($info1) {
throw new Throwable('This contains no sensitive information.');
}
/**
* Main
*
* @param string[] args
*/
public static function main($args) {
try {
self::calledWithSensitiveInformation('Could be a password...');
} catch (Throwable $t) {
$t->clearStackTraceArguments();
$t->printStackTrace();
}
}
}
?>
@thekid
Copy link
Author

thekid commented Mar 23, 2012

This is how the output looks when executing the test class:

$ xp issue136.ThrowableTest
Exception lang.Throwable (This contains no sensitive information.)
  at issue136.ThrowableTest::calledWithSensitiveInformation((0x8)'1 arg(s)') [line 31 of ThrowableTest.class.php]
  at issue136.ThrowableTest::main((0x8)'1 arg(s)') [line 0 of StackTraceElement.class.php]
  at php.ReflectionMethod::invokeArgs((0x8)'2 arg(s)') [line 102 of Method.class.php]
  at lang.reflect.Method::invoke((0x8)'2 arg(s)') [line 91 of class.php]

🔑

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment