Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Namespaces #14

Open
hikari-no-yume opened this issue Nov 16, 2014 · 5 comments
Open

Namespaces #14

hikari-no-yume opened this issue Nov 16, 2014 · 5 comments

Comments

@hikari-no-yume
Copy link
Contributor

Blueberry doesn't seem to handle this just now, so how should it? You could go for the most obvious approach of just adding use and use backslashes like PHP. On the other hand, there might be other approaches. We could use something other than the backslash, but that would mean you'd be typing, say, Foo::Bar normally but Foo\Bar in strings containing function names to be called... so it's probably not a good idea.

@gosukiwi
Copy link
Owner

Namespaces are great, I think we should avoid the \ and go for something simpler, like Foo:Bar:Baz and just compile them to PHP use clauses.

I think I was still considering if Blueberry should be compatible with old PHP, so for example, you could use __constructor or just create a method with the class name, and Blueberry would just compile it.

But namespaces must be added, and if we are adding them I guess we could eventually change the generated arrays to [] instead of array().

For now, just implementing them with use should be okay though. I guess the only discussion point would be on which syntax to use.

@hikari-no-yume
Copy link
Contributor Author

Namespaces are great, I think we should avoid the \ and go for something simpler, like Foo:Bar:Baz and just compile them to PHP use clauses.

The problem with Foo:Bar:Baz is that if you make a string function name and try to call it, you'd have to switch back to native PHP \ (e.g. $x = "Foo\Baz\Bar"; $x();). To be honest, I don't really have a problem with \. Using that saves other characters to be used for other things, too.

Also, what do you mean by "compile them to PHP use clauses"? use just makes an alias, you can reference things directly with Foo\Bar\Baz.

I think I was still considering if Blueberry should be compatible with old PHP, so for example, you could use __constructor or just create a method with the class name, and Blueberry would just compile it.

Old PHP, as in PHP 4? I'm pretty sure PHP 5's always had __constructor.

But namespaces must be added, and if we are adding them I guess we could eventually change the generated arrays to [] instead of array().

That could be a compiler option. Although, well, PHP 5.3 has reached EOL. It's still very much in use, but it's not going to be an issue soon. Outputting array() for compatibility for a while hardly hurts, though.

@gosukiwi
Copy link
Owner

Yeah, the proposed array() change was just to modernize everything a bit, but it really doesn't hurt at all to keep it as it is. About the use clause, I just ment the use statement, just compile them to PHP's use basically.

Yeah I see your point, we could certainly get away with using : but we'd have to patch edge cases and I don't think it's worth, at least for now.

I'm not sure how many things we'd have to update to implement namespaces, but it shouldn't be too hard, most likely the grammar, identifiers and method calls.

Also, I don't know if it's possible to do

a = 'Foo\Bar'
a()

In Blueberry, it's been a while! If it's not possible shouldn't be too hard to do though.

@hikari-no-yume
Copy link
Contributor Author

Ooh, good point, I'm not sure that is possible. You'd have to do $a(); but I don't think Blueberry ever generates variable function calls like that.

@gosukiwi
Copy link
Owner

Now that there's a scope manager, maybe function calls can be smarter now. I'll check that out.

Edit: Nevermind, it's already implemented 😋

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants