- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2
Type safety
        Greg Bowler edited this page Jul 1, 2023 
        ·
        5 revisions
      
    Type safety in programming languages such as PHP offers several advantages, which can lead to more robust, maintainable, and reliable code.
The Session class implements the TypeSafeGetter interface that is shared throughout multiple other PHP.Gt repositories.
Session implements the following functions:
- getString(string $name):?string
- getInt(string $name):?int
- getFloat(string $name):?float
- getBool(string $name):?bool
- getDateTime(string $name):?DateTimeInterface
- getObject(string $name, class-string<T> $className):?T
- Along with a function for getting a mixedtype,get(string $name):mixed.
These type-safe functions allow your code to be written in a way that knows exactly what data types to expect when being supplied data from the session. This can catch errors early, enhance readability/maintainability, and provide much better IDE support such as autocompletion.
In the next section, learn about how to organise session data using namespaces.
Php.Gt/Session is a separately maintained component of PHP.Gt/WebEngine