xp-framework/rfc — Issue #55: Make xp::stringOf() fatal error safe
Author: thekid
Created: 2011-10-17 15:46:31+00:00
State: closed
Labels: framework, implemented

Scope of Change
====
The xp::stringOf() core utility will be rewritten no longer to use
var_export().

Rationale
====
The PHP function var_export() can cause fatal errors in certain situations:

```
Fatal error: var_export(): Cannot use output buffering in output
buffering display handlers
in [...]/skeleton/util/log/LogAppender.class.php
on line 41

```

Functionality
====
The xp::stringOf() utility will return a string representation of a given
argument depending on its type:

Strings
----
The value is returned with enclosing double quotes:

```
"String"

```

Booleans
----
The value returned represents the two states of a boolean, TRUE and FALSE,
as follows:

```
true
false

```

Null and xp::null()
----
The representation of both of these null references is always:

```
null

```

Numerics
----
For both int and float values, the PHP string representation of these is
returned:

```
1.4
-1.2
-10
6100

```

Objects
----
An instance of any class extending lang.Object will have its toString()
method called. The results therefore depend on the implementation.

In case the optional callToString argument is set to default, the
representation will be the same as for any other object (e.g. stdClass).
The member variables are printed directly whereas the values
associated with them are printed using xp::stringOf():

```
fully.qualified.ClassName {
__id => "0.82536100 1139511047"
value => "String"
length => 6
offset => 1
}

```

Arrays
----
An array is represented by its key/value pairs. As there is no way to
separated "numeric arrays" [ 1, 2, 3] from hashmaps [ a => b, b => c ]
all arrays are treated as hashmaps, its keys being directly printed,
its values applied via xp::stringOf():

```
[
0 => 1
1 => 2
2 => 3
]

[
foo => "bar"
bar => 2,
baz => TestString(6) { String }
]

```

Resources
----
A resource is represented by its type and id:

```
resource(type= stream, id= 24)

```

Security considerations
====
n/a

Speed impact
====
Slower, because userland code will be used.

Dependencies
====
n/a

Related documents
====

Implementation
----
- http://xp-framework.net/downloads/rfc0055.diff
Patch against lang.base.php

- http://xp-framework.net/downloads/StringOfTest.class.phps
Testcase

Places where var_export() is used
----

```
# classname
-- ------------------------------------------------
3 text.parser.DaemonMailParser
3 com.google.soap.search.GoogleSearchResult
2 xml.soap.interop.Round2BaseClient
2 xml.soap.SOAPMessage
2 net.xp_framework.webservices.interop.Round2Handler
2 com.microsoft.format.chm.CHMFile
1 xml.uddi.BusinessList
1 xml.soap.SOAPFaultException
1 xml.soap.Parameter
1 xml.XMLFormatException
1 util.log.LogCategory
1 util.log.LogAppender
1 util.Hashmap
1 text.StringUtil
1 text.PHPTokenizer
1 security.cert.X509Certificate
1 rdbms.Peer
1 rdbms.DataSet
1 rdbms.DBEvent
1 peer.sieve.SieveClient
1 peer.mail.Message
1 peer.irc.IRCConnection
1 org.htdig.HtdigResultset
1 org.htdig.HtdigEntry
1 org.gnu.readline.ReadLine
1 lang.Thread
1 lang.Object

```