zephir-lang / zephir

Zephir is a compiled high-level language aimed to ease the creation of C-extensions for PHP
https://zephir-lang.com
MIT License
3.29k stars 466 forks source link

Concat does not work with global properties #2063

Open sergeyklay opened 4 years ago

sergeyklay commented 4 years ago

Zephir Code

namespace Bug;

class ClassPropertyConcat
{
    private store = "";

    public function add(string value) -> void
    {
        let this->store .= value;
    }

    public function add2(string value) -> void
    {
        let this->store = this->store . value;
    }

    public function get() -> string
    {
        return this->store;
    }
}

Test

--TEST--
Test me
--SKIPIF--
<?php include __DIR__ . 'skipif.inc'; ?>
--FILE--
<?php
$test = new Bug\ClassPropertyConcat();
var_dump($test->get());

$test->add2('phalcon');
$test->add2(' framework');
var_dump($test->get());

$test = new Bug\ClassPropertyConcat();
var_dump($test->get());

// This does not works
$test->add('phalcon');
$test->add(' framework');
var_dump($test->get());
?>
--EXPECT--
string(0) ""
string(17) "phalcon framework"
string(0) ""
string(17) "phalcon framework"

Output

string(0) ""
string(17) "phalcon framework"
string(0) ""
string(10) " framework" 
sergeyklay commented 4 years ago

Possible workaround

    public function add(string value) -> void
    {
        string store;

        let store = this->store;
        let store .= value;
        let this->store = store;
    }

Actually we're used this in such way always.

sergeyklay commented 4 years ago

/cc @niden