Closed CezaryDanielNowak closed 9 years ago
This is a nice idea
var1?
will be compiled to:
isset($var1) && ($var1 === true)
we will work on this :)
It should also work in more complex usage:
someVar = _POST['field']?['subfield']
will be compiled to:
$someVar = isset($_POST['field']) ? $_POST['field']['subfield'] : null;
or
result = someFunc?()
will be compiled to:
$result = function_exists('someFunc') ? someFunc() : null;
I think, it may conflict with bool ? true : false;
statement...
I'am adding a part of this feature dc88f9e2d183363ade34c49e8497626876945600 see this example http://mammouth.wamalaka.com/#try:{{%0Aif%28var1%3F%29%0A%20%20%20echo%28var1%29%0Am%20%3D%20bool%20%3F%20true%20%3A%20false%0A}}
Thanks for fast reply :)
m = somObject?.test
usagem = somearray?[12]
usage@korpirkor, do you know any PHP method that check if variable exists (any type of variable)??
still some issues. try:
{{
if(_GET['lista']?)
echo 'list isset !'
}}
{{
if(obj.field?)
echo 'field isset !'
}}
{{
field = 'someField'
if(obj{field}?)
echo 'list isset !'
}}
{{
if(@field?)
echo 'field isset !'
}}
hey @korpirkor, now you can do something like: http://mammouth.wamalaka.com/#try:{{%0Aif%28_GET[%27lista%27]%3F%29%0A%20%20%20%20echo%28%27list%20isset%20!%27%29%0Aif%28obj.field%3F%29%0A%20%20%20%20echo%28%27field%20isset%20!%27%29%0Afield%20%3D%20%27someField%27%0Aif%28obj{field}%3F%29%0A%20%20%20%20echo%28%27list%20isset%20!%27%29%20%20%0Aif%28%40field%3F%29%0A%20%20%20%20echo%28%27field%20isset%20!%27%29%0A}}
{{
if(_GET['lista']?)
echo('list isset !')
if(obj.field?)
echo('field isset !')
field = 'someField'
if(obj{field}?)
echo('list isset !')
if(@field?)
echo('field isset !')
}}
but remember in Mammouth, functions call should be used with parentheses echo(arg)
The commit changes: 78412b4896f46024a39801e9bd1bbd7b3d317e4c
Cool, thanks !
regarding parentheses in echo: echo is not a standard function, it's language construct, that even in PHP can be used without (
and )
; as described here: https://github.com/btwael/mammouth/issues/18
Make it work without (
and )
would make writing code much more natural and easy
@CezaryDanielNowak Finally mammouth support this one as you described in your second comment ;)
Hey, It would be cool if we have "?" character as isset(...), like in coffeeScript;