Rumah >pembangunan bahagian belakang >tutorial php >Bagaimana untuk Mengakses Hartanah Kelas dengan Ruang dalam Nama Mereka?
Accessing Properties with Spaces in Class Objects
This question explores how to access class properties that contain spaces in their names. Consider the following example, wherein a stdClass object has properties named "[Sector]" and "[Date Found]":
<p>stdClass Object ([Sector] => Manufacturing [Date Found] => 2010-05-03 08:15:19)</p>
While accessing "[Sector]" using $object->Sector is straightforward, retrieving "[Date Found]" requires a different approach.
To access properties with spaces, enclose the property name within curly braces ({}). For instance, the following code snippet retrieves the value of "[Date Found]":
$object->{'Date Found'}
By utilizing this method, developers can efficiently access properties with spaces, ensuring flexibility and convenience in handling complex object structures.
Atas ialah kandungan terperinci Bagaimana untuk Mengakses Hartanah Kelas dengan Ruang dalam Nama Mereka?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!