CreateObject()
The CreateObject function takes different arguments depending on the value of the first argument:
CreateObject('com', class, context, serverName)
CreateObject('component', component-name)
CreateObject('corba', context, class, locale)
CreateObject('java', class [, context])
CreateObject('webservice', urltowsdl, [, portname])
Warning
In Lucee 5, this function has been deprecated in favour of the new object()
syntax (reference needed). The only difference is that the new Object()
syntax automatically calls the init()
method. In line with our commitment to CFML, this function will never be dropped from the language and you are safe to use it going forward.
CreateObject( type=string, classname=object, context=object, delimiterOrVersion=object );
Returns: any
Examples
dump( label:"CreateObject in java", var:createObject('java','java.util.HashMap'));
dump( label:"CreateObject with init()", var:createObject('java',"java.lang.StringBuffer").init());
All these examples are all functionally identical
Except that the new Object()
syntax automatically calls the init()
method
dump( var=createObject("component", "org.lucee.cfml.http"), expand=false );
// but even "component" is optional for cfcs
dump( var=createObject("org.lucee.cfml.http"), expand=false );
// the modern new Object() syntax is also dynamic
dump(var=new "org.lucee.cfml.http"(), expand=false);
dump(var=new org.lucee.cfml.http(), expand=false);
cfc = "org.lucee.cfml.http";
dump(var=new "#cfc#"(), expand=false);
See also
- Components (CFCs)
- Java
- Objects
- Web services
- Core CFML Language
- MavenLoad()
- <cfimport>
- Search Issue Tracker
- Search Lucee Test Cases (good for further, detailed examples)