In PHP, how do I concatenate strings with strong typing?

In PHP, you can concatenate strings using the dot (.) operator. Here’s a simple example to illustrate strong typing and how to concatenate strings.

Keywords: PHP, string concatenation, strong typing

Description: This example demonstrates how to concatenate strings in PHP while ensuring type safety.

<?php function concatenateStrings(string $str1, string $str2): string { return $str1 . $str2; } $firstName = "John"; $lastName = "Doe"; $fullName = concatenateStrings($firstName, " " . $lastName); echo $fullName; // Output: John Doe ?>

Keywords: PHP string concatenation strong typing