Skip to content

Add support for closures, loops, classes in REPL #4

Description

@scottdavis

This was bugging me for awhile and i hacked away for about 2.5 hours trying to figure out a work about but
example:

> $foo = function() {return 'bar';}
> 
Uncaught exception with command:
Fatal error executing php: PHP Fatal error:  Uncaught exception 'Exception' with message 'Serialization of 'Closure' is not allowed' in /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.U3N9Oo:18
Stack trace:
#0 /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.U3N9Oo(18): serialize(Array)
#1 {main}
  thrown in /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.U3N9Oo on line 18

Exception: Serialization of 'Closure' is not allowed in /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.U3N9Oo on line 18

Call Stack:
    0.0004     635040   1. {main}() /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.U3N9Oo:0
    0.0009     637576   2. serialize() /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.U3N9Oo:18

Same goes for defining functions and classes
function:

> function foo() {return 'bar';}
> 
Uncaught exception with command:
Fatal error executing php: PHP Parse error:  syntax error, unexpected T_STRING, expecting '(' in /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.8CUHcL on line 12

Parse error: syntax error, unexpected T_STRING, expecting '(' in /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.8CUHcL on line 12
> 

Classes:

> class Foo {}
> 
Uncaught exception with command:
Fatal error executing php: PHP Parse error:  syntax error, unexpected T_CLASS in /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.Pk4qgL on line 12

Parse error: syntax error, unexpected T_CLASS in /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.Pk4qgL on line 12
> 

While i had a work around working the storing of $_ and $__out are not possible when you create a a special case even "foreach" will explode using serialization

foreach(range(0,10) as $i) { echo $i; }
> 
Uncaught exception with command:
Fatal error executing php: PHP Parse error:  syntax error, unexpected T_FOREACH in /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.mXsYfJ on line 12

Parse error: syntax error, unexpected T_FOREACH in /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.mXsYfJ on line 12
> 

Solution is avoid serialization and store the code input unserialized in a file and keep appending to it and re-executing, As for returning output some string parsing may be in order to find variables and var_dump-ing them may be in order or just rely or just print tokenize the last returnable line;

edit: fixed typo's my brain is fried

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions