phalcon/cphalcon · error · Phalcon\Di\Exceptions\SetterInjectionRequiresInstance

The definition has setter injection parameters but the…

Error message

The definition has setter injection parameters but the constructor didn't return an instance

What it means

The service definition contains a 'calls' (setter injection) block, but constructing the class did not yield an object (constructor returned null/non-object), so setter methods cannot be invoked on it.

Solutions

  1. Ensure the class named in 'className' instantiates to a real object (constructors must not return values)
  2. Remove the 'calls' block if the service is not meant to be setter-injected
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at phalcon/Di/Service/Builder.zep:87 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21). Data as JSON: /api/errors/50e5937f888294d3. Report an issue: GitHub.

Appendix: source

Thrown at phalcon/Di/Service/Builder.zep:87

            if fetch arguments, definition["arguments"] {
                /**
                 * Create the instance based on the parameters
                 */
                let instance = create_instance_params(
                    className,
                    this->buildParameters(container, arguments)
                );
            } else {
                let instance = create_instance(className);
            }
        }

        /**
         * The definition has calls?
         */
        if fetch paramCalls, definition["calls"] {
            if unlikely typeof instance !== "object" {
                throw new SetterInjectionRequiresInstance();
            }

            if unlikely typeof paramCalls != "array" {
                throw new SetterParametersMustBeArray();
            }

            /**
             * The method call has parameters
             */
            for methodPosition, method in paramCalls {
                /**
                 * The call parameter must be an array of arrays
                 */
                if unlikely typeof method != "array" {
                    throw new MethodCallMustBeArray(methodPosition);
                }

                /**

View on GitHub (pinned to b7419de9cd)