tpunt / phactor

An implementation of the Actor model for PHP
BSD 3-Clause "New" or "Revised" License
61 stars 5 forks source link

Serialising closures in arrays #6

Open tpunt opened 6 years ago

tpunt commented 6 years ago

Closures cannot be serialised inside of arrays. This is because arrays are simply serialised with PHP's internal serialiser. Closures require special handling with serialisation, and so arrays will need to be serialised differently if this is going to work. The ph_hashtable_t type should be reusable for this, so it should be a matter of mapping PHP's hash table to phactor's hash table.

Example:

<?php

use phactor\{ActorSystem, Actor, ActorRef};

$as = new ActorSystem(1);

class A extends Actor
{
    public function __construct(array $a){}
    public function receive(){}
}

$a = new ActorRef(A::class, [[function(){}]], 'a');

ActorSystem::shutdown();