Browse files

Wrote some note about value types.

  • Loading branch information...
1 parent fcf8062 commit ec871cd479a59fa73d8b0c6b49174ae81c7cb915 @dahlia dahlia committed Dec 17, 2009
Showing with 26 additions and 0 deletions.
  1. +26 −0 README.markdown
26 README.markdown
@@ -205,6 +205,32 @@ Lisp. It is a just synonym for PHP [`null`][null] value.
+About value types and refernece types
+According to the typing method of PHP, primitive types e.g. boolean, integer,
+float, string, array behave as value type. They are always copied when they
+passed into arguments or returned from a called function. For example,
+`arr` is empty from beginning to end in the following code.
+ (define arr (array))
+ (set-at! arr "element")
+Such behavior is not problem for scalar types e.g. boolean, integer, float,
+string because they are immutable, but can be problem for arrays.
+However you know objects behave as reference type in PHP if you are good at
+PHP, and there are `ArrayObject` class and its subclass `Lisphp_List`. They
+and arrays have the same interface, so you can use these class instead of
+ (use <ArrayObject>)
+ (define arr (<ArrayObject>))
+ (set-at! arr "element")
+ (define lis (list))
+ (set-at! arr "element")
Author and license

0 comments on commit ec871cd

Please sign in to comment.