-
-
Notifications
You must be signed in to change notification settings - Fork 2
Overview
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
mixed
type,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.
Session keys are addressable by their name, but can be nested using namespacing in order to encapsulate their data between different areas of your application. It's possible to load session data from nested namespaces by using a dot to separate namespaces, like this: $session->getString("somewhere.deep.inside.NAME")
.
[Read more about namespaces][namespaces].
// Link to sub-page
In the next section we will learn about how type safety is enforced.
Php.Gt/Session is a separately maintained component of PHP.Gt/WebEngine