Q: Does a colon :
in an array key have any special significance?
From the manual:
An array can be created by the array()
language construct. It takes as parameters any number of comma-separated key => value pairs.
array( key => value
, ...
)
While I was investigating what the Exception Object is set to, I created an error condition and put this line in-
print_r($ex);
Then in the web page produced looked at the source and it produces output like this-
Exception Object
(
[message:protected] => DB connection error: SQLSTATE[28000] [1045] Access denied for user 'test'@'localhost' (using password: YES)
[string:Exception:private] =>
Is the colon :
in [message:protected]
significant or is the key to the key => value pair literally message:protected
?
$ex
is not an array but rather an object. This is how print_r
is printing it, indicating with :protected
that the message
field is marked as protected
in the Exception
class.
The colon doesn't have any special meaning in the arrays.
$ex
is not an array, it is an object. Objects are more complicated data structures than arrays. What you see is a textual representation of the state of this object.
The developers decided to use a similar representation as it is used for arrays, and they use the colon separation for giving further information about the attributes of the object.
The colon has no meaning, and you won't be able to access a field with e.g. $ex['message:protected'].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With