PHP: Exception when specifying compound primary_unit in SimpleNamespace
Referring to the python reference implementation, it is possible to specify a compound primary_unit (e.g.: [ 'distinct_id', 'country' ] ) when setting up a SimpleNamespace. However, in PHP an exception is thrown in _getSegment() when an array of units is specified:
SimpleNamespace.php:_getSegment() line 174: $assignment->segment = new Random\RandomInteger( ['min' => 0, 'max' => $this->num_segments - 1], ['unit' => $this->inputs[$this->primary_unit]] );
$this->inputs can't be indexed by $this->primary_unit, which is an array. Both parity with python and the helper function SimpleNamespace.php:setPrimaryUnit($value) (where scalar $value is converted to an array automatically), suggest that compound units would be supported.
The following sample program exercises the issue:
use \Vimeo\ABLincoln\Namespaces\SimpleNamespace; use \Vimeo\ABLincoln\Experiments\SimpleExperiment; use \Vimeo\ABLincoln\Operators\Random as Random;
class MyExperiment extends SimpleExperiment { public function assign($params, $inputs) { $params->button_color = new Random\WeightedChoice( ['choices'=>['red', 'blue'], 'weights' => [ 0.5, 0.5 ] ], $inputs); } }
class MyNamespace extends \Vimeo\ABLincoln\Namespaces\SimpleNamespace { public function setup() { $this->name = 'My Namespace'; $this->num_segments = 10; $this->primary_unit = [ 'distinct_id', 'country' ]; } public function setupExperiments() { $this->addExperiment('My Experiment', MyExperiment, 5); } }
$ns = new MyNamespace(['country' => 'US', 'distinct_id' => 'slkf982-fjfs894hg-ishgfjgh']);
print $ns->get('button_color');