-* 1.12.4 (2013-XX-XX)
+* 1.13.0 (2013-XX-XX)
- * n/a
+ * enforced usage of named arguments after positional ones
* 1.12.3 (2013-04-08)
},
"extra": {
"branch-alias": {
- "dev-master": "1.12-dev"
+ "dev-master": "1.13-dev"
}
}
}
{# or skip the format value by using a named argument for the timezone #}
{{ "now"|date(timezone="Europe/Paris") }}
-You can also use both positional and named arguments in one call, which is not
-recommended as it can be confusing:
+You can also use both positional and named arguments in one call, in which
+case positional arguments must always come before named arguments:
.. code-block:: jinja
- {# both work #}
{{ "now"|date('d/m/Y H:i', timezone="Europe/Paris") }}
- {{ "now"|date(timezone="Europe/Paris", 'd/m/Y H:i') }}
.. tip::
#ifndef PHP_TWIG_H
#define PHP_TWIG_H
-#define PHP_TWIG_VERSION "1.12.4-DEV"
+#define PHP_TWIG_VERSION "1.13.0-DEV"
#include "php.h"
*/
class Twig_Environment
{
- const VERSION = '1.12.4-DEV';
+ const VERSION = '1.13.0-DEV';
protected $charset;
protected $loader;
if (!is_int($name)) {
$named = true;
$name = $this->normalizeName($name);
+ } elseif ($named) {
+ throw new Twig_Error_Syntax(sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $this->getAttribute('type'), $this->getAttribute('name')));
}
+
$parameters[$name] = $node;
}
$name = $this->normalizeName($param->name);
if (array_key_exists($name, $parameters)) {
+ if (array_key_exists($pos, $parameters)) {
+ throw new Twig_Error_Syntax(sprintf('Arguments "%s" is defined twice for %s "%s".', $name, $this->getAttribute('type'), $this->getAttribute('name')));
+ }
+
$arguments[] = $parameters[$name];
unset($parameters[$name]);
} elseif (array_key_exists($pos, $parameters)) {
--TEMPLATE--
{{ date|date(format='d/m/Y H:i:s P', timezone='America/Chicago') }}
{{ date|date(timezone='America/Chicago', format='d/m/Y H:i:s P') }}
-{{ date|date(timezone='America/Chicago', 'd/m/Y H:i:s P') }}
{{ date|date('d/m/Y H:i:s P', timezone='America/Chicago') }}
--DATA--
date_default_timezone_set('UTC');
04/10/2010 08:45:00 -05:00
04/10/2010 08:45:00 -05:00
04/10/2010 08:45:00 -05:00
-04/10/2010 08:45:00 -05:00
--- /dev/null
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+class Twig_Tests_Node_Expression_CallTest extends PHPUnit_Framework_TestCase
+{
+ public function testGetArguments()
+ {
+ $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date'));
+ $this->assertEquals(array('U'), $node->getArguments('date', array('format' => 'U')));
+ }
+
+ /**
+ * @expectedException Twig_Error_Syntax
+ * @expectedExceptionMessage Positional arguments cannot be used after named arguments for function "date".
+ */
+ public function testGetArgumentsWhenPositionalArgumentsAfterNamedArguments()
+ {
+ $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date'));
+ $node->getArguments('date', array('timestamp' => 123456, 'Y-m-d'));
+ }
+
+ /**
+ * @expectedException Twig_Error_Syntax
+ * @expectedExceptionMessage Arguments "format" is defined twice for function "date".
+ */
+ public function testGetArgumentsWhenArgumentIsDefinedTwice()
+ {
+ $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date'));
+ $node->getArguments('date', array('Y-m-d', 'format' => 'U'));
+ }
+}
+
+class Twig_Tests_Node_Expression_Call extends Twig_Node_Expression_Call
+{
+ public function getArguments($callable, $arguments)
+ {
+ return parent::getArguments($callable, $arguments);
+ }
+}