Null passed to a date argument type

Full Null Support Enabled

Null passed as argument to a function

<cfargument name=“OrderDateEnd” type=“date” required=“No”>

Railo - All Good

Lucee - ERROR : Argument (OrderDateBegin) is of invalid type, can’t cast Null value to value of type [date]

Just another annoying little difference that makes migrating painful

Hi @elliot_russo,

Yes, It will throw error because it compare date data type with string(if we passed an empty string to argument). Please ensure the data type of the arguments before we send to function.

Lucee & Railo working in same way as expexted

Lucee & Railo working in same way as expexted

Actually, it breaks in Lucee and works in Railo as the post mentioned. I’m
not saying it SHOULDN’T throw an error, but they are not working in the
same way. That’s the issue for people migrating.

CF Mitrah as Lance pointed out, Lucee is different from Railo, which is tedious… I’m guessing railo was less pure. Why we need to be pure with a typeless language is beyond me, it is meant to be about convenience, anyway I digress.

Personally, I think the Railo way of doing it is better. But that’s just my
personal preference. I think less errors thrown for bad data inputs and it
just works as expected (even if not correct) is a good thing.

Then again, I mess up and type on occasion. :slight_smile:

Some kind of support for optionals would be very convenient. For example, in Swift, you can define a function like this:

func funcName (someParam: Int?)

As a result of the question mark sigil, you can pass an int or a nil without complaint. It would be nice to be able to have something like this in lucee:

function doSomethingWithADate (required date? expirationDate) {...

whereby you could set an expiration date, or clear an expiration date by sending a null value…

Obviously having some notion of union types would be a more complex superset of this behavior, e.g.:

function doSomethingWithADate (required date | null expirationDate) {...

None of this is going to happen; I just muse about it every time I have to use an any type and then manually write a type-checker to achieve the same thing. Duck-typing is great and all, but sometimes it would would be nice to enforce a type and also allow it to be nulled…

the date? type would be like c# nullable date type wrapper. Nice idea.

I guess I can implement the if date eq date types minvalue test, that assumes that to be a null

Some implementation of this would save (me, at least) so much extra hand-written tooling around simulating optional types. I guess the implementation question is whether a null makes sense as the terminal minvalue of a date type… Maybe the semantics aren’t that important. I think optional types would be a really nice feature for Lucee that developers might discover they never knew they were missing. So to speak.

an issue is that databases allow nulls for dates, that is why it would be useful for me. I’ll just have to implement date arguments as a string datatype. Wouldn’t have been a problem if Railo hadn’t allowed me to do in the first place.