Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
[zendframework/zendframework#3055] Remove array to string conversion …
Browse files Browse the repository at this point in the history
…notice

- Removes an array to string conversion notice when nested arrays are
  provided as values
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/AbstractValidator.php
Expand Up @@ -303,7 +303,7 @@ protected function createMessage($messageKey, $value)
) {
$value = get_class($value) . ' object';
} elseif (is_array($value)) {
$value = '[' . implode(', ', $value) . ']';
$value = var_export($value, 1);
} else {
$value = (string) $value;
}
Expand Down
12 changes: 12 additions & 0 deletions test/AbstractTest.php
Expand Up @@ -10,6 +10,7 @@

namespace ZendTest\Validator;

use ReflectionMethod;
use Zend\I18n\Translator\Translator;
use Zend\Validator\AbstractValidator;

Expand Down Expand Up @@ -227,6 +228,17 @@ public function testDefaultTranslatorMethods()
$this->assertTrue(AbstractValidator::hasDefaultTranslator());
}

public function testMessageCreationWithNestedArrayValueDoesNotRaiseNotice()
{
$r = new ReflectionMethod($this->validator, 'createMessage');
$r->setAccessible(true);

$message = $r->invoke($this->validator, 'fooMessage', array('foo' => array('bar' => 'baz')));
$this->assertContains('foo', $message);
$this->assertContains('bar', $message);
$this->assertContains('baz', $message);
}

/**
* Ignores a raised PHP error when in effect, but throws a flag to indicate an error occurred
*
Expand Down

0 comments on commit f8c969a

Please sign in to comment.