Skip to content

Commit 79e400b

Browse files
authored
Merge pull request #39 from WebFiori/dev
Fix to a Bug in Setting Property Value
2 parents 36f6759 + 23da8a4 commit 79e400b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

webfiori/json/Property.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public function setAsObject(bool $bool) {
242242
* @since 1.0
243243
*/
244244
public function setName(string $name) : bool {
245-
$keyValidity = self::_isValidKey($name, $this->getStyle());
245+
$keyValidity = self::isValidKey($name, $this->getStyle());
246246

247247
if ($keyValidity === false) {
248248
return false;
@@ -293,12 +293,14 @@ public function setStyle(string $style) {
293293
* @since 1.0
294294
*/
295295
public function setValue($val) {
296-
if (is_subclass_of($val, 'webfiori\\json\\JsonI')) {
296+
$this->datatype = gettype($val);
297+
298+
if ($this->getType() == 'object' && is_subclass_of($val, 'webfiori\\json\\JsonI')) {
297299
$this->value = $val->toJSON();
298300
} else {
299301
$this->value = $val;
300302
}
301-
$this->datatype = gettype($val);
303+
302304
}
303305
/**
304306
* Checks if the key is a valid key string.
@@ -312,7 +314,7 @@ public function setValue($val) {
312314
*
313315
* @since 1.0
314316
*/
315-
private static function _isValidKey($key, $style = 'kebab') {
317+
private static function isValidKey($key, $style = 'kebab') {
316318
$trimmedKey = trim($key);
317319

318320
if (strlen($trimmedKey) != 0) {

0 commit comments

Comments
 (0)