silverstripe/silverstripe-framework — pull request #2113 by CheeseSucker (2013-06-18 19:11:38+00:00)
Title: FIX: ViewableData::obj() would sometimes return an empty object

For instance, this happens when these criteria are met:
1) No casting has been specified for a method in $casting.
2) A template accesses the field without any casting
3) Any casts by the template will now yield an empty object.

After a brief look at the commit history, it can seem like this bug is several years old, unless it is a side-effect of other changes in the code.

== Steps to reproduce ==
Add two methods to be accessed by a template. Make sure you do not define an entry in $casting for them:
public function Testus() {
return "Tet1";
}

public function Testus2() {
return "Tet2";
}

Add this to a template:

First access:

"$Testus" : "$Testus.XML"

"$Testus2.XML" : "$Testus2"

Second access:

"$Testus" : "$Testus.XML"

"$Testus2.XML" : "$Testus2"

Open the page in a browser, and you will get:
First access:
"Tet1" : ""
"Tet2" : "Tet2"

Second access:
"Tet1" : ""
"" : "Tet2"

We see that any cast can yield an empty string.