# RFC: call_time_pass_by_reference

- Status: Implemented (PHP 5.3)
- Authors: Steph Fox sfox@php.net
- Date: 2008-05-21
- Version: 1.0
- Original: https://wiki.php.net/rfc/calltimebyref
- Page: https://externals.io/rfc/calltimebyref
- 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

## Discussions on the mailing list

- [RFC: allow_call_pass_by_reference](https://externals.io/message/37773.md) — started on 2008-05-21, 20 messages

---

## Introduction

This RFC aims to clarify the situation with call-time pass-by-ref in PHP 5.3.

## History

Before PHP 4.0 was released, `allow_call_time_pass_reference` was introduced as a means of retaining back compatibility with PHP 3, at the point where returning by reference from a function declaration became possible \[1\]. By default, the INI switch has been On since inception \[2\]. The warning (formerly `E_COMPILE_WARNING` but currently `E_DEPRECATED`) is only thrown if the INI switch is Off. You therefore need to **explicitly** switch off the directive in order to discover that the behaviour is deprecated.

At the time `allow_call_time_pass_reference` was introduced, php.ini-recommended was interestingly referred to as 'php.ini-optimized'. Over the years, it has become fairly standard to regard php.ini-recommended as 'production settings'; things like `display_errors=Off` and `log_errors=On` have helped this perception along. From inception, `allow_call_time_pass_reference` was switched `Off` in php.ini-recommended but `On` in php.ini-dist and by default. For the last 8 years, therefore, the first anyone is likely to have known about their code being less than kosher is when it went live.

Even in the current php.ini-recommended, the switch is attributed only to 'Code cleanliness'. The full entry in the heading about changed settings reads:

```
; - allow_call_time_pass_reference = Off     [Code cleanliness]
;     It's not possible to decide to force a variable to be passed by reference
;     when calling a function.  The PHP 4 [sic] style to do this is by making the
;     function require the relevant argument by reference.
```

In fact, allowing values to be passed by reference is the default behaviour in PHP, and has been from PHP 4.0 beta right up to PHP 5.3.

## Reality Check

In some circumstances, on some platforms, passing values by reference can actually speed up your code. In most cases, though - and for all when it comes to large arrays - it carries a performance penalty. If you make use of by-ref for performance reasons on a given platform, that optimization will not be portable.

## Future

The directive is completely gone from CVS HEAD \[3\]. The effect of this originally was that a new-to-many `E_STRICT` would be thrown when values are passed by reference. However, it's been moved to `E_DEPRECATED` recently. In either case, it will no longer be possible to turn the warning off.

## Proposal

Switch `allow_call_time_pass_reference` off by default in PHP\_5\_3 branch. At present there is no warning when running PHP under default settings, whereas in PHP 6 there will be a 'deprecated' warning given and no means of turning it off.

## References

1. \[1\] [http://cvs.php.net/viewvc.cgi/ZendEngine2/zend\_compile.c?r1=1.85&amp;r2=1.86](http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.c?r1=1.85&r2=1.86)

1. \[2\] [http://cvs.php.net/viewvc.cgi/php-src/main/main.c?r1=1.157&amp;r2=1.158](http://cvs.php.net/viewvc.cgi/php-src/main/main.c?r1=1.157&r2=1.158)

1. \[3\] [http://cvs.php.net/viewvc.cgi/php-src/main/main.c?r1=1.676&amp;r2=1.677](http://cvs.php.net/viewvc.cgi/php-src/main/main.c?r1=1.676&r2=1.677)

### Comments

currently allow\_call\_time\_pass\_reference is set to Off in both php.ini-production and php.ini-development for 5.3, and Call-time pass-by-reference was removed from 5.4, so this RFC is implemented/obsolete.
