Skip to content

var_type #1935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Closed

var_type #1935

wants to merge 14 commits into from

Conversation

Fleshgrinder
Copy link
Contributor

@Fleshgrinder Fleshgrinder commented Jun 7, 2016

Proposal for a gettype() successor, originates from and closes #1932 in favor of this PR.

Magic strings are bad in any programming context, repeating the same string over
and over again too even if everyone knows what they mean. It increases the
chance of typos and requires string searches throughout the whole code base to
find usages. Usage of constants helps to mitigate this problem and keeps changes
localized.
Additionally sorted everything alphabetically, helps to identify the right
line very fast.
@Fleshgrinder Fleshgrinder mentioned this pull request Jun 12, 2016
6 tasks
@smalyshev smalyshev added the RFC label Jun 14, 2016
@KalleZ
Copy link
Member

KalleZ commented Jun 23, 2016

Wouldn't it have been more interesting if this was a language construct instead, we might even be able to perform some compile time optimizations.

e.g.:

$language = 'PHP';
if($language typeof string) { ... }

Given we already reserve the type keywords, this should not be a problem.

@Fleshgrinder
Copy link
Contributor Author

This was discussed on the mailing list and will be answered in the RFC, short answer no. The reason is simple, we do not want to have yet another operator and rather extend the functionality of the existing instanceof operator. Also note that the purpose of this function is not meant for what you are doing in your example, the idiomatic way for that is currently if (is_string($language)) in PHP.

@HallofFamer
Copy link

I agree that extending the functionality of instanceof is a better idea, $var instanceof string sounds good to me.

case IS_TRUE:
RETURN_VAR_TYPE(ZEND_STR_BOOL);

/* case IS_FLOAT: */

Choose a reason for hiding this comment

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

Has this been left in for documentation purposes? Or is this a case that should be added back in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now only documentation purpose but hopefully in the future it becomes the actual case. See future scope of the RFC.

@Fleshgrinder Fleshgrinder mentioned this pull request Jun 26, 2016
5 tasks
Fleshgrinder and others added 7 commits July 2, 2016 16:27
It is true that both literal string values `true` and `false` are sometimes required in userland software in the context of type related functionalities. However, the should not be provided through the `TYPE_*` constants simply because it would introduce too much inconsistency since they are not types in userland PHP.
It was simply a stupid mistake and I deleted the `TYPE_FLOAT` constant instead of the `TYPE_FALSE` constant.
@nikic
Copy link
Member

nikic commented Jul 23, 2016

Closing here as the RFC has been declined.

@nikic nikic closed this Jul 23, 2016
@Fleshgrinder Fleshgrinder deleted the rfc/var-type branch April 30, 2017 23:39
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.

6 participants