Exception not work

I update php to 5.6.17 and exception stopped working.

Who know what happened?

example

try
{
    if ($Model->create($params->toArray()))
    {
        ...
    }
    else
    {
        throw new \Exception(implode('<br>', $Model->getMessages()));
    }
}
catch (\Exception $e)
{
    $this->flash->error($e->getMessage());
}

os centos 6

on 1.3.4 work

on 2.0.9 not work



1.1k

Hi,

have you tried this, to isolate the problem :

try
{
    throw new \Exception("error testing");
}
catch (\Exception $e)
{
    $this->flash->error($e->getMessage());
}


11.5k

this work

Hi,

have you tried this, to isolate the problem :

try
{
   throw new \Exception("error testing");
}
catch (\Exception $e)
{
   $this->flash->error($e->getMessage());
}


1.1k

then the problem is in the other part : create returns always true...

  if ($Model->create($params->toArray()))
    {
    }


11.5k

why always?

https://docs.phalconphp.com/en/latest/reference/models.html#create-update-with-confidence

if ($robot->create() == false) {
    echo "Umh, We can't store robots right now: \n";
    foreach ($robot->getMessages() as $message) {
        echo $message, "\n";
    }
} else {
    echo "Great, a new robot was created successfully!";
}

then the problem is in the other part : create returns always true...

 if ($Model->create($params->toArray()))
   {
   }


1.1k

"Always" in your example...

What is the implementation of the class of $model, what are the values of $params



11.5k
edited Feb '16

model with not null fields

and now all models can be saved, wtf?

if ($form->isValid())
{
$params = $form->getEntity();
}

"Always" in your example...

What is the implementation of the class of $model, what are the values of $params



1.1k
edited Feb '16

how are declared "not null" constraints ?

Are nulls replaced by an empty string at the insertion?



11.5k
CREATE TABLE `settings` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `is_active` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1',
    `key` VARCHAR(24) NOT NULL DEFAULT '',
    `key_value` VARCHAR(24) NOT NULL DEFAULT '',
    `name` VARCHAR(48) NOT NULL DEFAULT '',
    `description` VARCHAR(512) NULL DEFAULT NULL,
    PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;

how are declared "not null" constraints ?

Are nulls replaced by an empty string at the insertion?



1.1k
edited Feb '16

if the fields "not null" have a default value in the database, it is normal, insertion is always possible, and create returns always true...\

remove a DEFAULT value and try again, you will see.



11.5k

but why in 1.3.4 its work?

if the fields "not null" have a default value in the database, it is normal, insertion is always possible, and create returns always true...



1.1k
edited Feb '16

I dont know,

Are you really sure that the only change is the transition to Phalcon2...



11.5k

i have two lxc containers: 1 php 5.5 phalcon1 2 php 5.6 with phalcon2

first work second none

I dont know too

I dont know,

Are you really sure that the only change is the transition to Phalcon2...



1.1k

have you tried (php 5.5 + phalcon1 2) and (php 5.6 + phalcon2) with the same Mysql server ?



11.5k

yes

have you tried (php 5.5 + phalcon1 2) and (php 5.6 + phalcon2) with the same Mysql server ?



1.1k

Strange, but the normal behavior is with Phalcon 2 and php 5.6

Not null fields with default values do not generate errors if the field is null