# [RFC][Discussion] Make compact function reports undefined passed variables

- Thread: https://externals.io/message/102012
- Original archive: https://news-web.php.net/php.internals/102012
- Started by Gabriel Caruso on 2018-04-02T09:17:43+00:00
- Messages: 7
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #102012 — Gabriel Caruso — 2018-04-02T09:17:43+00:00

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

Hello dear internals, how are you?

I'd like to propose a new RFC to PHP's core, but as this one contains a BC
Break, let's discussed it before making anything official.

A couple of days ago, while discussing some [Coding Standards rules for
Doctrine, forbidden the `compact` function](
https://github.com/doctrine/coding-standard/pull/49), an argument caught my
attention:

> The `compact` function var does not report undefined variables.

Looking in [the `compact` documentation](https://secure.php.net/compact),
this is even emphasizes:

> Any strings that are not set will simply be skipped.

I couldn't figure out why this is done this way, but, here's what I'd like
to propose: make the `compact` function starts to report undefined passed
variables for it.

With [only 2 lines of code](
https://github.com/php/php-src/compare/master...carusogabriel:warning-unknow-compact-variable),
this is possible, but, of course, this is a BC Break.

Let me know your opinion on that, and perhaps, make it happen!

Regards,
-- 
Gabriel Caruso

---

## #102013 — Pieter Hordijk — 2018-04-02T11:21:47+00:00

URL: https://externals.io/message/102012#102013 · In reply to: #102012

----- Original Message -----
> From: "Gabriel Caruso" <carusogabriel34@gmail.com>
> To: "internals" <internals@lists.php.net>
> Sent: Monday, April 2, 2018 11:17:43 AM
> Subject: [PHP-DEV] [RFC][Discussion] Make compact function reports undefined passed variables

> Hello dear internals, how are you?
> 
> I'd like to propose a new RFC to PHP's core, but as this one contains a BC
> Break, let's discussed it before making anything official.
> 
> A couple of days ago, while discussing some [Coding Standards rules for
> Doctrine, forbidden the `compact` function](
> https://github.com/doctrine/coding-standard/pull/49), an argument caught my
> attention:
> 
> > […]
> 
> Looking in [the `compact` documentation](https://secure.php.net/compact),
> this is even emphasizes:
> 
> > […]
> 
> I couldn't figure out why this is done this way, but, here's what I'd like
> to propose: make the `compact` function starts to report undefined passed
> variables for it.
> 
> With [only 2 lines of code](
> https://github.com/php/php-src/compare/master...carusogabriel:warning-unknow-compact-variable),
> this is possible, but, of course, this is a BC Break.
> 
> Let me know your opinion on that, and perhaps, make it happen!
> 
> Regards,
> --
> Gabriel Caruso

Hey Gabriel,

What I am missing here is the reason why we should break well defined behavior of existing functions.

How is the BC break for all existing code justified?

Pieter

---

## #102014 — Gabriel Caruso — 2018-04-02T11:45:47+00:00

URL: https://externals.io/message/102012#102014 · In reply to: #102013

>
> Hey Gabriel,
>
> What I am missing here is the reason why we should break well defined
> behavior of existing functions.
>
> How is the BC break for all existing code justified?
>
> Pieter
>


Hi Pieter.

 > What I am missing here is the reason why we should break well defined
behavior of existing functions.

This is something I'd like to discuss about `compact`. I'd like to know why
we skip undefined variables instead of report them. `compact` is use in a
large scale by the MVC community, by passing variables in the controller
and using them in the view.

> How is the BC break for all existing code justified?

I'd like to start report this undefined variables. Would be one more way to
prevent code-smell. IMHO this belongs to the core, not to the userland.


Thanks,

-- 
Gabriel Caruso

---

## #102015 — Pieter Hordijk — 2018-04-02T12:08:50+00:00

URL: https://externals.io/message/102012#102015 · In reply to: #102014

> Hi Pieter.

> > […]


> Hi Pieter.

> > […]

> This is something I'd like to discuss about `compact`. I'd like to know why we
> skip undefined variables instead of report them. `compact` is use in a large
> scale by the MVC community, by passing variables in the controller and using
> them in the view.

> > […]

> I'd like to start report this undefined variables. Would be one more way to
> prevent code-smell. IMHO this belongs to the core, not to the userland.

> Thanks,

> --
> Gabriel Caruso

Regardless of the why it is like that the fact of the matter is that it is and imho
you would need a really good reason to break existing code.

I still don't don't see your reason for it. Nor do I see how it is a code smell atm.

---

## #102016 — Ivan Enderlin — 2018-04-04T07:32:43+00:00

URL: https://externals.io/message/102012#102016 · In reply to: #102012

Hello,

Yes, a thousand yes. Silently ignoring undefined variables is a source 
of multiple bugs. Emiting a warning is a small BC break comparing to the 
benefits.

Regards.


> Hello dear internals, how are you?
>
> I'd like to propose a new RFC to PHP's core, but as this one contains a BC
> Break, let's discussed it before making anything official.
>
> A couple of days ago, while discussing some [Coding Standards rules for
> Doctrine, forbidden the `compact` function](
> https://github.com/doctrine/coding-standard/pull/49), an argument caught my
> attention:
>
> > […]
> Looking in [the `compact` documentation](https://secure.php.net/compact),
> this is even emphasizes:
>
> > […]
> I couldn't figure out why this is done this way, but, here's what I'd like
> to propose: make the `compact` function starts to report undefined passed
> variables for it.
>
> With [only 2 lines of code](
> https://github.com/php/php-src/compare/master...carusogabriel:warning-unknow-compact-variable),
> this is possible, but, of course, this is a BC Break.
>
> Let me know your opinion on that, and perhaps, make it happen!
>
> Regards,

---

## #102026 — Andrea Faulds — 2018-04-09T21:54:50+00:00

URL: https://externals.io/message/102012#102026 · In reply to: #102016

And the determined can prefix with an @ if they want similar to old 
behaviour :)

Ivan Enderlin wrote:
> Hello,
>
> Yes, a thousand yes. Silently ignoring undefined variables is a source
> of multiple bugs. Emiting a warning is a small BC break comparing to the
> benefits.
>
> Regards.
>

-- 
Andrea Faulds
https://ajf.me/

---

## #102027 — bjorn.x.larsson@telia.com — 2018-04-11T13:49:56+00:00

URL: https://externals.io/message/102012#102027 · In reply to: #102026

And by that one could argue that the BC break is negligible :)
Anyway, I think this is a clear improvement!

Regards
--
//Björn Larsson


Den 2018-04-09 kl. 23:54, skrev Andrea Faulds:

> And the determined can prefix with an @ if they want similar to old 
> behaviour :)
>
> Ivan Enderlin wrote:
> > […]
