for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Phossa Project
*
* PHP version 5.4
* @category Library
* @package Phossa2\Shared
* @copyright Copyright (c) 2016 phossa.com
* @license http://mit-license.org/ MIT License
* @link http://www.phossa.com/
*/
/*# declare(strict_types=1); */
namespace Phossa2\Shared\Error;
* ErrorAwareTrait
* Implementation of ErrorAwareInterface
* @author Hong Zhang <[email protected]>
* @see ErrorAwareInterface
* @version 2.0.22
* @since 2.0.22 added
trait ErrorAwareTrait
{
* error message
* @var string
* @access protected
protected $error = '';
* error code
protected $error_code = '';
* 0 or '0000' etc means no error, = ''
* @var bool
protected $zero_empty = true;
* {@inheritDoc}
public function hasError()/*# : bool */
return '' === $this->error_code;
}
public function getError()/*# : string */
return $this->error;
public function getErrorCode()/*# : int */
return $this->error_code;
public function setError(
/*# string */ $message = '',
/*# string */ $code = ''
)/*# : bool */ {
$this->error = (string) $message;
// zero ?
$zcode = (string) $code;
if ($this->zero_empty && '' === str_replace('0', '', $zcode)) {
$this->error_code = '';
} else {
$this->error_code = $zcode;
return false;
public function copyError(ErrorAwareInterface $obj)
if ($obj->hasError()) {
$this->setError($obj->getError(), $obj->getErrorCode());