9
davide
7y

Ok guys, you surely want to kill me, but I so love PHP in this case

Comments
  • 4
    in C# it would have been:
    if(!int.TryParse(strVal, out int intVal) && intVal != 2 && intVal != 3){
    return;
    }

    in Swift:
    guard let intVal = Int(strVal), intVal == 2 || intVal == 3 else{
    return
    }

    for me being able to do that it will make a mess in my code, maybe its just me ...
  • 1
    @gitpush yes but I don't want to use try and catch 😀
  • 0
    @davide ooh that looks much better than try catch code, but doesn't it produce exceptions? Not a PHP dev just wondering
  • 0
    @gitpush These functions doesn't produce an exception. They return only a boolean value
  • 1
    never mind me, just saw the is_number function so no chance for an exception when parsing it to int
  • 0
    int val = 0;
    std::from_chars(idOperation, std::next(idOperation, length), val);
    if (val != 2 && val != 3) return;
  • 1
    Ruby:

    return unless idOperation.is_a? Number
    return unless [2,3].includes? idOperation.to_i
  • 0
    Haskell:

    Just kidding, you never have to check that shit in Haskell.
Add Comment