17888[FEATURE] Utility function to deprecate public method calls
Commit message
Review
-
Code review CR 0
-
Verified V 0
Issues 1
Files 1
Review log 28
Show 3 earlier messages
-
Markus Klein commented on patch set 1 05/27/13, 17:19
How exactly would you distinguish between a public call and a protected call within the method then? Your usage example would drop a line in the log, even if the call was correctly done from inside the class. -
Markus Klein commented on patch set 1 05/27/13, 17:19
(1 inline comment) Do you have an idea how many methods are affected with this situation: public, because needed internally. If these methods are used frequently internally, creating the backtrace would be quite some overhead IHMO. -
Markus Klein commented on patch set 1 05/27/13, 17:19
Philipp: The advantage of this approach is still that we can also track method calls of public methods, which can not be made protected as they are used internally by other Core classes.
-
Markus Klein commented on patch set 1 05/27/13, 17:19
I guess we're not talking about the same thing. I was talking about methods we CAN NOT make protected, because of internal usage in other classes, but MAY NOT be accessed from outside. -
Xavier Perseguers commented on patch set 1 05/27/13, 17:19
Methods which are already marked as public but "do not use" should be evaluated on a case-by-case if it's still true but will much probably not have to be turned into protected methods. We don't have access to "friendly" visibility in PHP (except when subclassing another class :D) and we have to live with that limitation. -
Christian Kuhn commented on patch set 1 05/27/13, 17:19
There might be a second solution for that (which won't work for properties, too): make methods protected right away, and implement some magic __call() that will be called then (i THINK that works, even if the method exists but is protected, should be tested). __call() could then throw some deprecated warning and call the originally requested method internally if it exists. This way we have no overhead in usual calls. -
Sebastian Michaelsen commented on patch set 1 05/27/13, 17:19
(1 inline comment) @Markus: No, when the call comes from within the same object no log entry is done (see inline comment)GeneralUtility.php:4911this condition ensures that only public usage is logged -
Sebastian Michaelsen commented on patch set 1 05/27/13, 17:19
@Philipp: I agree that GeneralUtility is not a good place for that, but the other deprecation methods are also there. Movin them all together to a better place (new utility class?) should be subject of another change -
Philipp Gampe commented on patch set 1 05/27/13, 17:19
Code looks good, but GeneralUtility is the wrong place IMHO. It would be better to move this function to one of the log classes. -
Philipp Gampe commented on patch set 1 05/27/13, 17:19
I would prefer to use __call and make the method protected right away. You would need a static array per class holding the former public method names and the deprecation version. Then you can check if the method was public before and log a deprecation message without loosing the speed in local calls. Check this for a start https://gist.github.com/pgampe/5066866 -
Philipp Gampe commented on patch set 1 05/27/13, 17:19
@Markus but it requires to load a another class, and do complex parsing which will be quite slow The __call approach allows to make methods protected right way, and allow "public" calls during the deprecation method. Afterwards, just the logic in __call is removed. -
Mr. Jenkins commented on patch set 1 05/27/13, 17:19
Build Successful https://ci.typo3.org/job/typo3-v4-core-gerrit/7271/ : SUCCESS -
Sebastian Michaelsen uploaded patch set 2 09/10/13, 07:03
-
Mr. Jenkins commented on patch set 2 09/10/13, 07:04
Build Successful https://ci.typo3.org/job/typo3-v4-core-gerrit/10597/ : SUCCESS -
Markus Klein commented on patch set 2 09/10/13, 07:45
Did you already evaluate the performance impact of the backtracing?GeneralUtility.php:4911ReplyOk, I had to read the php doc first to get the intention of this comparison. Maybe you could describe that step a bit more in the comment. -
Sebastian Fischer voted on patch set 2 CR +1 09/10/13, 09:14
-
Sebastian Michaelsen commented on patch set 2 09/10/13, 09:20
@Markus Klein: The backtracing is only done if the deprecation log ist activated. The deprecation log is a tool to test an installation for deprecated behaviour and it's recommended to switch it off in Live context. In my opinion performance is not really an issue here. -
Markus Klein commented on patch set 2 CR +1 09/10/13, 09:35
Alright then. Fine with me. -
Sebastian Michaelsen uploaded patch set 3 09/10/13, 10:00
-
Mr. Jenkins commented on patch set 3 09/10/13, 10:01
Build Successful https://ci.typo3.org/job/typo3-v4-core-gerrit/10601/ : SUCCESS -
Sebastian Michaelsen commented on patch set 3 09/10/13, 10:02
I put in "require_once 'DebugUtility.php';" just like it is done in GeneralUtility::logDeprecatedFunction(). That's because there might be deprecated stuff before the autoloader is initialized. -
Markus Klein commented on patch set 3 09/10/13, 10:15
GeneralUtility.php:4920Do we any chance to detect whether the call was made from outside the TYPO3 Namespace? Otherwise we'll get lots of deprecations if we call a public method from another class in Core, which is public but not part of the API. -
Philipp Gampe commented on patch set 3 09/10/13, 10:26
GeneralUtility.php:4905please check with isset() first in order to avoid warnings, also in most cases this variable will hold a string. You should use empty() here to catch all possible values (FALSE; array(), 0, '0', NULL, ...) -
Claus Due commented on patch set 3 CR -1 09/10/13, 10:30
I vote that this should either not be merged or should be done in a way not using debug_backtrace(). The reasons are many but the primary one: you're logging the parent method call, not the entire call stack. Besides, enableDeprecationLog is on by default in new 6.2 installs and uses the "file" target. Imagine how this log file would simply EXPLODE if this was ever released to the wild. Please consider adding a new configuration toggle to enable this particular log as it can be expected to create huge amounts of noise in the log. Alternative suggestion: pass arguments for class and method, recommend using __CLASS__ and __METHOD__ as parameters. It's faster than any other way, it is copy/paste or search/replace friendly and it avoids abusing the debugging features of PHP. And add a new configuration toggle, off by default, which toggles logging of these public methods specifically. -
Claus Due commented on patch set 3 09/10/13, 10:36
Addendum: I absolutely advise against using any sort of magic method call to log these function calls. Once again there are many reasons but the most important ones: * You would have to either have a list of or some way to reflect your way to knowing if a function was previously public - which means a performance drop across the line. * You would need to let it fail if the real method does not exist. * And finally: __call only works if the method does not exist; implication: every single method that needs to be switched from public to protected must also be renamed, causing the worst and biggest chaos I can imagine. -
Markus Klein commented on patch set 3 10/10/13, 16:58
Sebastian do you have an answer to Claus' comment? If not I guess this is a dead end and you should consider to abandon this patch. -
Claus Due commented on patch set 3 06/11/14, 11:26
Abandon please. -
Sebastian Michaelsen abandoned the change 06/25/14, 11:04
no time to work on it anymore