Skip to content

Commit

Permalink
Merge pull request #1357 from sjinks/issue-1349
Browse files Browse the repository at this point in the history
[FIX] Phalcon\Forms\Form::getMessages() produces PHP error if form is valid
  • Loading branch information
Phalcon committed Oct 9, 2013
2 parents f90743d + 41889b2 commit c153b94
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
20 changes: 8 additions & 12 deletions ext/forms/form.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,7 @@ PHP_METHOD(Phalcon_Forms_Form, isValid){
*/
PHP_METHOD(Phalcon_Forms_Form, getMessages){

zval *by_item_name = NULL, *messages, *element_messages = NULL;
zval *element = NULL;
zval *by_item_name = NULL, *messages;
HashTable *ah0;
HashPosition hp0;
zval **hd;
Expand Down Expand Up @@ -579,16 +578,13 @@ PHP_METHOD(Phalcon_Forms_Form, getMessages){
object_init_ex(return_value, phalcon_validation_message_group_ce);
phalcon_call_method_noret(return_value, "__construct");

phalcon_is_iterable(messages, &ah0, &hp0, 0, 0);

while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {

PHALCON_GET_HKEY(element, ah0, hp0);
PHALCON_GET_HVALUE(element_messages);

phalcon_call_method_p1_noret(return_value, "appendmessages", element_messages);

zend_hash_move_forward_ex(ah0, &hp0);
if (Z_TYPE_P(messages) == IS_ARRAY) {
phalcon_is_iterable(messages, &ah0, &hp0, 0, 0);

while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
phalcon_call_method_p1_noret(return_value, "appendmessages", *hd);
zend_hash_move_forward_ex(ah0, &hp0);
}
}

PHALCON_MM_RESTORE();
Expand Down
12 changes: 12 additions & 0 deletions ext/tests/issue-1349.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Phalcon\Forms\Form::getMessages() produces PHP error if form is valid - https://github.com/phalcon/cphalcon/issues/1349
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php
$form = new \Phalcon\Forms\Form;
$form->add(new \Phalcon\Forms\Element\Text('name'));
$form->isValid(array('name' => 'John'));
assert(get_class($form->getMessages(false)) == 'Phalcon\Validation\Message\Group');
?>
--EXPECT--

0 comments on commit c153b94

Please sign in to comment.