-
-
Notifications
You must be signed in to change notification settings - Fork 4
Migration issues: v0.5.0
Nelson Martell edited this page Apr 13, 2017
·
4 revisions
This only applies to your custom classes extending
NelsonMartell\Objectclass (or subclass).
Properties by default uses get|set now as getter/settter prefix (instead of get_|set_). If you had a getter method called get_Name for your Name property, will be throws an exception when you try to use it:
<?php #src/SomeClass.php
namespace MyAwesomeNamespace;
use NelsonMartell\Object;
class SomeClass extends Object
{
public function __construct($name)
{
parent::__construct();
unset($this->Name);
$this->_name = $name;
}
public $Name;
private $_name = '';
public function get_Name()
{
return $this->_name;
}
}<?php #src/index.php
use MyAwesomeNamespace\SomeClass;
$girl = new SomeClass('Nathaly');
// This throws a BadMethodCallException:
// Unable to get the property value in "MyAwesomeNamespace\SomeClass" class.
echo $obj->Name;In the last SomeClass class example, you just need to rename get_Name method to getName:
<?php #src/SomeClass.php
# . . .
public function getName()
{
return $this->_name;
}
# . . . You can "Bring" back the old behavior by setting getterPrefix and setterPrefix static properties in your constructor:
<?php
namespace MyAwesomeNamespace;
use NelsonMartell\Object;
use NelsonMartell\PropertiesHandler;
class SomeClass extends Object
{
// Why use it again? More info: http://php.net/manual/en/language.oop5.traits.php.
use PropertiesHandler;
public function __construct($name)
{
parent::__construct();
unset($this->Name);
static::getterPrefix = 'get_';
// static::setterPrefix = 'set_';
$this->_name = $name;
}
public $Name;
private $_name = '';
public function get_Name()
{
return $this->_name;
}
}NOTE: There is a bug when toString method is used on classes with 'customized' prefixes. Use solution 1️⃣ instead.
PHP: Nelson Martell Library - © 2015-2017 Nelson Martell