Reflection/List properties: Difference between revisions

add Perl 6
(added php)
(add Perl 6)
Line 140:
exampleProperty Td,N,V_exampleProperty 3.14
</pre>
 
=={{header|Perl 6}}==
 
You can get a list of an object's attributes (instance variables) using <tt>.^attributes</tt>.<br>
Each is represented as an <tt>Attribute</tt> object that contains a bunch of info:
 
<lang perl6>class Foo {
has $!a = now;
has Str $.b;
has Int $.c is rw;
}
 
my $object = Foo.new: b => "Hello", c => 42;
 
for $object.^attributes {
say join ", ", .name, .readonly, .container.^name, .get_value($object);
}</lang>
 
{{out}}
<pre>
$!a, True, Any, Instant:1470517602.295992
$!b, True, Str, Hello
$!c, False, Int, 42
</pre>
 
Public attributes (in this case, <tt>$.b</tt> and <tt>$.c</tt>) are really just attributes for which the compiler also auto-generates a method of the same name. See [[Reflection/List_methods#Perl_6]].
 
=={{header|PHP}}==
Anonymous user