Do any of you know why we have not seen a more Object Oriented approach in PHP when it comes to Strings. It seems so reasonable to adopt a mechanism much like JavaScript's where every string is an object. For instance, I wrote a small little snippet that would highlight a few benefits when it comes to strings.
Code: Select all
class String {
public $raw;
public $htmlEntities;
public $length;
function __construct( $string ) {
$this->raw = $string;
$this->htmlEntities = htmlentities( $this->raw );
$this->length = strlen( $this->raw );
}
}
Code: Select all
object(String)[1]
public 'raw' => string 'Hello, World' (length=12)
public 'htmlEntities' => string 'Hello, World' (length=12)
public 'length' => int 12
Please note that I have not done research on any possible PHP "String Objects" out there, I just sort of wanted to spectate feedback from this community.
Anyway, I appreciate any responses.