Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1025996
D276.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Jun 13, 5:53 PM
Size
3 KB
Mime Type
text/x-diff
Expires
Sat, Jun 14, 5:53 PM (4 h, 24 m)
Engine
blob
Format
Raw Data
Handle
661651
Attached To
D276: INP-1662 - Add methods for handling deprecations
D276.diff
View Options
Index: branches/5.2.x/core/kernel/globals.php
===================================================================
--- branches/5.2.x/core/kernel/globals.php
+++ branches/5.2.x/core/kernel/globals.php
@@ -928,6 +928,75 @@
throw new InvalidArgumentException(sprintf('Unknown escape strategy "%s"', $strategy));
}
+
+ /**
+ * Mark a method as deprecated and inform when it has been used.
+ *
+ * The current behavior is to trigger a user deprecation notice in Debug Mode.
+ * This method is to be used in every method that is deprecated.
+ *
+ * @param string $method The method that was called.
+ * @param string $version The version that deprecated the method.
+ * @param string|null $replacement The method that should have been called.
+ *
+ * @return void
+ */
+ public static function deprecatedMethod($method, $version, $replacement = null)
+ {
+ $application =& kApplication::Instance();
+
+ if ( !$application->isDebugMode() ) {
+ return;
+ }
+
+ $msg = '%1$s is <strong>deprecated</strong> since version %2$s';
+
+ if ( !is_null($replacement) ) {
+ @trigger_error(sprintf($msg . '! Use %3$s instead.', $method, $version, $replacement), E_USER_DEPRECATED);
+ }
+ else {
+ @trigger_error(sprintf($msg . ' with no alternative available.', $method, $version), E_USER_DEPRECATED);
+ }
+ }
+
+ /**
+ * Mark a method argument as deprecated and inform when it has been used.
+ *
+ * This method is to be used whenever a deprecated method argument is used.
+ * Before this method is called, the argument must be checked for whether it was
+ * used by comparing it to its default value or evaluating whether it is empty.
+ * For example:
+ *
+ * if ( !$deprecated ) {
+ * kUtil::deprecatedArgument(__METHOD__, '5.2.2');
+ * }
+ *
+ * The current behavior is to trigger a user deprecation notice in Debug Mode.
+ *
+ * @param string $method The method that was called.
+ * @param string $version The version that deprecated the argument used.
+ * @param string|null $message A message regarding the change.
+ *
+ * @return void
+ */
+ public static function deprecatedArgument($method, $version, $message = null)
+ {
+ $application =& kApplication::Instance();
+
+ if ( !$application->isDebugMode() ) {
+ return;
+ }
+
+ $msg = '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s';
+
+ if ( !is_null($message) ) {
+ @trigger_error(sprintf($msg . '! %3$s', $method, $version, $message), E_USER_DEPRECATED);
+ }
+ else {
+ @trigger_error(sprintf($msg . ' with no alternative available.', $method, $version), E_USER_DEPRECATED);
+ }
+ }
+
}
/**
Index: branches/5.2.x/core/kernel/utility/debugger.php
===================================================================
--- branches/5.2.x/core/kernel/utility/debugger.php
+++ branches/5.2.x/core/kernel/utility/debugger.php
@@ -724,6 +724,7 @@
'Fatal Error' => self::ROW_TYPE_ERROR,
'Warning' => self::ROW_TYPE_WARNING,
'Notice' => self::ROW_TYPE_NOTICE,
+ 'Deprecation Notice' => self::ROW_TYPE_NOTICE,
);
return $error_map[$this->getErrorNameByCode($data['no'])];
@@ -1462,9 +1463,8 @@
);
if ( defined('E_DEPRECATED') ) {
- // since PHP 5.3
- $error_map['Notice'][] = E_DEPRECATED;
- $error_map['Notice'][] = E_USER_DEPRECATED;
+ // Since PHP 5.3.
+ $error_map['Deprecation Notice'] = array(E_DEPRECATED, E_USER_DEPRECATED);
}
foreach ($error_map as $error_name => $error_codes) {
Event Timeline
Log In to Comment