Skip to main content
Participant
May 27, 2010
Answered

Instantiate using "new" not working on init() method

  • May 27, 2010
  • 1 reply
  • 422 views

Hi,

I'm instantiating an object using "new" and calling my init() constructor with passing 4 parameters but I'm getting error that the params are required (Please see below). This works using "createobject", that's fine but I wanted to use the "new" to create an object. Can somebody give some info why this is not working? Thank you.

The  SHOPPINGCARTDSN parameter to the INIT function is required but was not  passed in.

<cfscript>
    o = new cfc.shop.discount().init(shoppingcartdsn: 'test', localDSN: 'tcb', starsDSN: 'testdsn', projectname: 'test');
    writeDump(o);
</cfscript>

    This topic has been closed for replies.
    Correct answer

    You don't have to call the init-Method when you instantiate your object with new. This is done by the new-function itself (even with parameters; pass the paramters to the object, not to the init-function)

    Try this:

    <cfscript>

         o = new cfc.shop.discount(shoppingcartdsn: 'test', localDSN: 'tcb', starsDSN: 'testdsn', projectname: 'test');

         writeDump(o);

    </cfscript

    1 reply

    Correct answer
    May 28, 2010

    You don't have to call the init-Method when you instantiate your object with new. This is done by the new-function itself (even with parameters; pass the paramters to the object, not to the init-function)

    Try this:

    <cfscript>

         o = new cfc.shop.discount(shoppingcartdsn: 'test', localDSN: 'tcb', starsDSN: 'testdsn', projectname: 'test');

         writeDump(o);

    </cfscript

    matt_xtrAuthor
    Participant
    May 28, 2010

    Hi!

    Thanks a lot for the new idea. I didn't know that the "new" function does this by itself. A good one to start the day!