# [RFC DISCUSSION] var_type

- Thread: https://externals.io/message/93900
- Original archive: https://news-web.php.net/php.internals/93900
- Started by Fleshgrinder on 2016-06-11T15:10:38+00:00
- Messages: 6
- RFC: var_type() (Declined) — https://externals.io/rfc/var_type.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #93900 — Fleshgrinder — 2016-06-11T15:10:38+00:00

URL: https://externals.io/message/93900#93900

I changed my initial proposal for typeof() to var_type() and would like
to start the discussion on it:

https://github.com/php/php-src/pull/1935

The functionality is straight forward.
-- 
Richard "Fleshgrinder" Fussenegger

---

## #94253 — Fleshgrinder — 2016-06-25T15:25:26+00:00

URL: https://externals.io/message/93900#94253 · In reply to: #93900

I finished the RFC:

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

-- 
Richard "Fleshgrinder" Fussenegger

---

## #94254 — Theodore Brown — 2016-06-25T17:57:27+00:00

URL: https://externals.io/message/93900#94254

>
> I finished the RFC:
>
> https://wiki.php.net/rfc/var_type
>

Thanks for this RFC! I think it's a great way to make PHP's
type system more consistent without breaking backwards
compatibility. I especially like that it would fix confusing
error messages like "Argument must be an instance of boolean,
boolean given."

I noticed that the "A Successor" section of the RFC still contains
a bunch of references to typeof (in the function signature and code
examples). Did you forget to change these to var_type?

Theodore Brown

---

## #94255 — Fleshgrinder — 2016-06-25T18:27:04+00:00

URL: https://externals.io/message/93900#94255 · In reply to: #94254

> Thanks for this RFC! I think it's a great way to make PHP's
> type system more consistent without breaking backwards
> compatibility. I especially like that it would fix confusing
> error messages like "Argument must be an instance of boolean,
> boolean given."
> 

Glad you like it. :)

Updating confusing error messages and other type related things will be
the next step that I take. This RFC and its function is just the beginning.


> I noticed that the "A Successor" section of the RFC still contains
> a bunch of references to typeof (in the function signature and code
> examples). Did you forget to change these to var_type?
> 

Indeed I overlooked them, thanks for the heads up will fix it right away
(in other words, when the wiki is back online).

-- 
Richard "Fleshgrinder" Fussenegger

---

## #94258 — Dan Ackroyd — 2016-06-26T10:31:56+00:00

URL: https://externals.io/message/93900#94258 · In reply to: #94253

Hi Richard,


> I finished the RFC:
>
> https://wiki.php.net/rfc/var_type
>

As other noted elsewhere by others, the name of the function is
slightly misleading for this case:

var_type(1 + 1);

However I don't have a better suggestion.

From the second half of the RFC:

> const TYPE_FALSE = 'false';
> const TYPE_TRUE = 'true';

Although as an implementation detail they are present in the engine,
those aren't types in userland. i.e. you can't do

function foo(true $i_only_accept_true)  {}

cheers
Dan

---

## #94259 — Fleshgrinder — 2016-06-26T10:42:52+00:00

URL: https://externals.io/message/93900#94259 · In reply to: #94258

> Hi Richard,
> 

Hi Dan!


> As other noted elsewhere by others, the name of the function is
> slightly misleading for this case:
> 
> var_type(1 + 1);
> 
> However I don't have a better suggestion.
> 

The name comes from Sara from the original typeof() discussion thread. I
understand the arguments of the people but as I already explained on
Reddit, the usage of var_type() on expressions like the above is nothing
anyone would ever do, especially if the TYPE_INT constant is exposed in
userland. One would only use it to get the type of the value that is
currently stored in a variable of which the type is unknown.

vat_type() or value_type() could be good choices as function name.
However, both would introduce new prefixes and I actually do not think
that this is a good idea because it will require people to remember more
and more and more prefixes which makes no sense. It is a declared goal
of this RFC to make is simpler for developers to find what the need
(aided by their IDE and brain). Remembering that you can get additional
information about a variable (its value, type, ...) via the super old
var_* prefix is definitely a good thing, shows visions, and an overall
goal. Note that I plan to provide a var_info() function in my next RFC
that builds upon this.

TL;DR I still like Sara's suggestion and intend to keep it.


> From the second half of the RFC:
> 
> > […]
> 
> Although as an implementation detail they are present in the engine,
> those aren't types in userland. i.e. you can't do
> 
> function foo(true $i_only_accept_true)  {}
> 

Yes, I also struggled to actually expose them (and write a comment for
them). I searched some code bases and found many usages of literal true
and false, this convinced me that there is a need for them. Introduction
of true and false as type declarations was also discussed and proposed
multiple times (did not make as of yet though).

I am definitely open to removing them again! Should we add a third poll?

-- 
Richard "Fleshgrinder" Fussenegger
