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.31k stars 466 forks source link

Zephir ignores namespace fallback policy #1345

Open Jurigag opened 8 years ago

Jurigag commented 8 years ago

What is namespace fallback policy:

http://php.net/manual/en/language.namespaces.fallback.php

This is causing that calls to php functions like is_uploaded_file and rest of php functions can't be mocked up in tests anyhow because zephir calls php function anyway.

Related - https://github.com/phalcon/cphalcon/pull/12352

I know there is probably wrong namespace and it should be Phalcon\Validation\Validator but i checked with it and not working anyway.

Even creating proxy class and trying diffrent namespaces there don't work :/

Tbh im not sure if there is even anyway to solve it since we have compiled extension, i guess not.

Jurigag commented 7 years ago

@sjinks could this be somehow solved? I guess it could potentially add big overhead so i think the best options would be something like zephir buildtest or something like this so any calls to php functions would work with namespace fallback policy? It could make possible to provide better tests coverage for phalcon.

sjinks commented 7 years ago

I think PHP does that at compile time…

Not sure if it is possible to implement this in Zephir as namespaced functions are mangled.

Say, test\test_func becomes test_test_func. And it seems like test\test\func becomes test_test_func either :-)

Jurigag commented 7 years ago

I just though that we could somehow intercept function calls in zephir(like xdebug is doing?) and check if in our active namespace we have same function defined and call it instead calling one from the global. I know this will add overhead that's why i was asking from some special option to compile like zephir buildtest

sjinks commented 7 years ago

Namespace is a syntactic sugar, there is no notion of namespaces at run time :-(

Jurigag commented 7 years ago

Oh okay then, too bad, then i guess i can close it :C

Jurigag commented 7 years ago

@sergeyklay