rfc:var-export-array-syntax

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
rfc:var-export-array-syntax [2020/03/29 17:48] googleguyrfc:var-export-array-syntax [2020/03/30 02:52] googleguy
Line 3: Line 3:
   * Date: 2020-03-29   * Date: 2020-03-29
   * Author: Sherif Ramadan, googleguy@php.net   * Author: Sherif Ramadan, googleguy@php.net
-  * Status: Draft+  * Status: Under Discussion
   * First Published at: http://wiki.php.net/rfc/var-export-array-syntax   * First Published at: http://wiki.php.net/rfc/var-export-array-syntax
  
Line 12: Line 12:
  
 ===== Proposal ===== ===== Proposal =====
-Instead of <code php>array(1, 2, 3)</code> ''var_export()'' would produce <code php>[1, 2, 3]</code>+Instead of 
 + 
 +<code php>array(1, 2, 3)</code> 
 + 
 +''var_export()'' would produce 
 + 
 +<code php>[1, 2, 3]</code> 
 + 
 +This will effect things like ''stdClass'' and ''set_state'' as well since they are cast to objects from array literals and they use the long-form array syntax above. 
 + 
 +So the following changes are also in effect: 
 + 
 +<code php> 
 +$obj = new stdClass; 
 +$obj->foo = "bar"; 
 +$obj->baz = "quix"; 
 + 
 +var_export($obj); 
 + 
 +/* 
 +Gives us: 
 +(object) array( 
 +   'foo' => 'bar', 
 +   'baz' => 'quix', 
 +
 + 
 +With the new change it would be 
 + 
 +(object) [ 
 +   'foo' => 'bar', 
 +   'baz' => 'quix', 
 +
 +*/ 
 +</code> 
 + 
 +The same happens for classes: 
 + 
 +<code php> 
 +class Foo { 
 +    public $bar = "baz"; 
 +
 + 
 +var_export(new Foo); 
 + 
 +/* 
 +Gives us: 
 +Foo::__set_state(array( 
 +   'bar' => 'baz', 
 +)) 
 + 
 +With the changes it would be: 
 +Foo::__set_state([ 
 +   'bar' => 'baz', 
 +]) 
 +*/ 
 +</code>
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 39: Line 94:
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
-The change only requires changing two lines in ''ext/standard/var.c'' (lines 530 and 540) to replace ''array ('' and '')'' with ''['' and '']''. See https://heap.space/xref/php-src/ext/standard/var.c?r=a9398056#530-540 for reference.+The change only requires changing two lines in ''ext/standard/var.c'' (lines 530 and 540) to replace ''array ('' and '')'' with ''['' and '']''. 
 + 
 +See https://heap.space/xref/php-src/ext/standard/var.c?r=a9398056#530-540 for reference.
  
 ===== Implementation ===== ===== Implementation =====
Line 45: Line 102:
 ===== References ===== ===== References =====
 https://heap.space/xref/php-src/ext/standard/var.c?r=a9398056#530-540 https://heap.space/xref/php-src/ext/standard/var.c?r=a9398056#530-540
 +
 +https://news-web.php.net/php.internals/109415
  
 ===== Rejected Features ===== ===== Rejected Features =====
  
rfc/var-export-array-syntax.txt · Last modified: 2020/04/10 09:24 by guilliamxavier