Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayAccess doesn't work in zephir-land #1400

Closed
Jurigag opened this issue Mar 2, 2017 · 3 comments
Closed

ArrayAccess doesn't work in zephir-land #1400

Jurigag opened this issue Mar 2, 2017 · 3 comments
Labels

Comments

@Jurigag
Copy link
Contributor

Jurigag commented Mar 2, 2017

Not sure if fetch keyword supports ArrayAccess interface. Doesn't seems so, check this PR for more phalcon/cphalcon#12670

It could be nice to implement it imho.

@Jurigag
Copy link
Contributor Author

Jurigag commented Mar 2, 2017

Well ArrayAccess interface doesn't work at all in zephir-land. Even isset or array["index"] when array is object implementing ArrayAcces doesn't work:

test.zep:

namespace Arraytest;

class Test implements \ArrayAccess
{
	protected test;

	public function __construct() {
		let this->test = [
			"one":1,
			"two":2,
			"three":3
		];
	}
	
	public function offsetSet(offset, value)
	{
		if is_null(offset) {
			let this->test[] = value;
		} else {
			let this->test[offset] = value;
		}
	}
	
	public function offsetExists(offset) {
		return isset this->test[offset];
	}
	
	public function offsetUnset(offset) {
		unset this->test[offset];
	}
	
	public function offsetGet(offset) {
		return isset this->test[offset] ? this->test[offset] : null;
	}
}

test2.zep:

namespace Arraytest;

class Test2
{
	public static function test()
	{
		var test;
		
		let test = new Test();
		var_dump(isset test["one"]);
		var_dump(test["one"]);
	}
}


test.php:

use Arraytest\Test2;
use Arraytest\Test;

Test2::test();
$test = new Test();
var_dump(isset($test["one"]));
var_dump($test["one"]);

Returns:

bool(false)
PHP Notice: Cannot use a scalar value as an array in arraytest/test2.zep on line 11 in /root/test.php on line
5

Notice: Cannot use a scalar value as an array in arraytest/test2.zep on line 11 in /root/test.php on line 5
NULL
bool(true)
int(1)

@Jurigag Jurigag changed the title Fetch ArrayAccess ArrayAccess doesn't work in zephir-land Mar 2, 2017
@Jurigag
Copy link
Contributor Author

Jurigag commented Mar 2, 2017

Looks like #1061 this issue was related but code to reproduce got deleted.

@sergeyklay
Copy link
Member

@dreamsxin Could you please take a look

@dreamsxin dreamsxin mentioned this issue Feb 21, 2019
3 tasks
Zephir Bugs automation moved this from Needs triage to Closed Feb 22, 2019
sergeyklay pushed a commit that referenced this issue Feb 23, 2019
@niden niden removed this from Closed in Zephir Bugs Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants