COMMUNITY

[PHP7] StringTools.trim() can be used on nulls

Hej,

I don’t know if it’s really a bug or something confusing me on the specs.
For example on javascript, StringTools.trim() will throw an exception when used on null, not in PHP7.
Looking in the Haxe `StringTools.trim(), there is nothing specified if it should or not throw exception in this case, how to deal with this kind of questions even for others methods on different targets please ? Should a same behaviour be defined in the Haxe STD for all targets or is it target specific and we must guess what will be the behaviour depending on target ?

Regarding null in std the behavior is usually either described in the method doc or Null<..> added to the argument type. If neither is present, then the behavior for null value is unspecified and may vary across targets and even across different versions of Haxe.

If you are sure a method in stdlib should have a specified behavior for null values, please raise an issue the compiler repo.

Hej Aleksandr,

Thanks for your answer.
Well, I don’t really know what should be the behaviour for that, There is nothing specified in the std, that was just my question in fact : What should it be ? :smiley:
I’ve also seen sometimes in some docs that is null is given so the behaviour is unspecified, but here it’s said nothing.

It’s just a bit weired to have to deal with something that seems so basic, in JS I’ve have to write if ( s != null && StringTools.trim( s ) != "" )and in PHP7 if( StringTools.trim( s ) != "" ) is enough, hard to write something cross-plateform.

You just write if ( s != null && StringTools.trim( s ) != "" ) for all targets and stay safe :slight_smile: