Allow construct Neuron with named arguments.

Example:

<?php
$instance = new Neuron(stringValue: 'Hello world', integerValue: 50,
boolValue: false);

echo $instance->stringValue; // "Hello world" will be printed.
?>

Also, is possible to send infinite params without names and his names
will be numeric similar as a non-asociatie array, but as Neuron object.

Example:

<?php
$str = 'Hello world';
$int = 50;
$con = false;

$instance = new Neuron($str, $int);

echo $instance->{0}; // "Hello world" will be printed.
?>
This commit is contained in:
KJ 2023-06-04 14:47:58 -04:00
parent 39a1f9d85a
commit eff0b86762

View File

@ -25,9 +25,15 @@ class Neuron {
/**
* __construct
*
* @param object|array $data
* @param array $data
*/
public function __construct(array|object $data = []) {
public function __construct(...$data) {
if (count($data) === 1 &&
isset($data[0]) &&
(is_array($data[0]) ||
is_object($data[0])))
$data = $data[0];
foreach($data as $key => $value)
$this->{$key} = $value;
}