Skip to content

Conversation

Danack
Copy link
Contributor

@Danack Danack commented Aug 14, 2016

Changes get_class() to disallow null being a valid parameter, as that behaviour is highly astonishing.

The ratio of the number of characters in the RFC to the actual code change, is too darn high.

https://wiki.php.net/rfc/get_class_disallow_null_parameter

@nikic nikic added the RFC label Aug 15, 2016
@nikic nikic changed the title Get class rfc get_class() disallow null parameter RFC Aug 15, 2016
@Danack
Copy link
Contributor Author

Danack commented Oct 10, 2016

The RFC was accepted 15-3.

@php-pulls php-pulls merged commit 9bbda76 into php:master Oct 10, 2016
@@ -1009,7 +1009,7 @@ ZEND_FUNCTION(get_class)
{
zval *obj = NULL;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "|o!", &obj) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|o", &obj) == FAILURE) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't the logic also be removed from source which handles obj == NULL at 1016 line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antanas-arvasevicius I don't think so. The parameter is still optional, and so calling get_class() returns the current scope, or gives a warning and returns false, if called from outside a class's scope.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, sorry. Right, I've missed that get_class() could be still a valid call. But it's now similar effect as get_called_class(), couldn't get_called_class() work in any methods and return current class name then get_class($object); would do only one thing, returns a class name of a given object and no more else :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antanas-arvasevicius get_called_class is aware of the 'late static binding' aka the real class, not the current scope class, so they are not equivalent. https://3v4l.org/ISkEZ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants