Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Wrote some note about value types.

  • Loading branch information...
commit ec871cd479a59fa73d8b0c6b49174ae81c7cb915 1 parent fcf8062
@dahlia dahlia authored
Showing with 26 additions and 0 deletions.
  1. +26 −0 README.markdown
View
26 README.markdown
@@ -205,6 +205,32 @@ Lisp. It is a just synonym for PHP [`null`][null] value.
[null]: http://php.net/manual/en/language.types.null.php
+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
+arrays.
+
+ (use <ArrayObject>)
+ (define arr (<ArrayObject>))
+ (set-at! arr "element")
+ (define lis (list))
+ (set-at! arr "element")
+
+
Author and license
------------------
Please sign in to comment.
Something went wrong with that request. Please try again.