Comments (17)
JS target uses the same approach: untyped __js__('alert(1)')
from haxe.
untyped
is bad for various reasons. It would be better to hide this as Lib.code('')
or something to that extent.
from haxe.
So should new generator support untyped
or implement somethind like Lib.code()
instead?
from haxe.
I guess we should still support untyped __php__
but encourage the alternative.
from haxe.
So what's the approved alternative? )
from haxe.
I don't really have a strong opinion about that, any normal field call will do.
from haxe.
I think php.Lib.code
is short and clear.
Can you use php
as PHP namespace BTW?
from haxe.
Additionally php.Lib.call
maybe var
should be done differently, physeq
is not needed I think. At least it wasn't in the old phpgen, don't know how you handle equality.
from haxe.
In python we have python.Syntax
and there's stuff for generating python expressions.
from haxe.
I don't really see how it would make much difference compared to untyped
though. It can be even worse, because untyped __php__
is an unbound var, while something like php.Syntax.pythonCode
is a normal function call from the analyzer POV, and it's going to make assumptions that it's a normal call, not something "magic" that is handled in the generator.
from haxe.
Yes but this allows us to introduce some @:magic
metadata for the analyzer. In the long run I would like to get rid of unbound variables entirely.
from haxe.
Have you guys looked at the solutions used by Typescript and scala.js for this general problem of calling into untyped external code? I know they're JS rather than PHP, but it's the same basic issue. They let you define a typed interface, like this scala.js for the Google maps JS lib:
trait MapOptions extends js.Object {
var backgroundColor: String = js.native
var center: LatLng = js.native
var disableDefaultUI: Boolean = js.native
var disableDoubleClickZoom: Boolean = js.native
...
}
I know it seems a bit of a pain, but they don't take long to knock up, and Typescript has a cool shared repo of these interfaces for all kinds of JS libraries.
You can then call methods and create objects from those JS libraries in a type-safe way, and the generated code is optimal too.
from haxe.
untyped is my biggest pain point currently (I'm writing a Wordpress plugin in Haxe and need to call into Wordpress functions loads) and I'd love to see it get a lot slicker. To take another example from how scalajs handles things, if you don't setup an interface (as above), you can just do this:
var arg2 = 3;
js.Dynamic.global.some_external_func("arg1", arg2)
Admittedly there's no more type-safety than with untyped, and scala.js has no idea whether some_external_func exists and how many args it takes, I just think it's a bit easier to read and write that than:
untyped __php__('some_external_func("arg1", $arg2)');
I can more easily see the arguments, at least. Maybe this syntactic sugar is possible?
from haxe.
Haxe has the same concept called externs: https://haxe.org/manual/lf-externs.html
from haxe.
Ah amazing, thank you. I'm very new to Haxe, these look great.
from haxe.
Here is an example: https://github.com/RealyUniqueName/haxe/blob/php7/std/php7/reflection/ReflectionProperty.hx
And here is original PHP class: http://php.net/manual/en/class.reflectionproperty.php
from haxe.
Implemented php7.Syntax
which purpose is to replace all untyped
code: https://github.com/RealyUniqueName/haxe/blob/php7/std/php7/Syntax.hx
from haxe.
Related Issues (20)
- Rename things which has names conflicting with PHP
- Write typed arrays in docblocks
- NativeStructArray HOT 6
- UTF-8 aware String functions HOT 4
- PSR-4 / PSR-1 Compliance HOT 2
- External storage for class metadata and reflexion HOT 2
- Call Boot initialization in each loaded class HOT 1
- Don't pass `null` for calls with missing optional args HOT 1
- App entry point. HOT 1
- Support String fields for Dynamic values HOT 1
- Cast HOT 1
- Exception, file is not generated HOT 1
- Map iteration HOT 2
- Invoke native PHP class constants HOT 2
- Special class for PHP syntax implementation HOT 1
- Avoid excess unsets HOT 1
- Add new reserved keywords from PHP 7.1 HOT 1
- Investigate StringBuf optimizations
- Mention `-D php7` in haxe manual
- Infinite recursion in `trace()` if object has circular references.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from haxe.