Skip to content

[BUG]: phalcon enforces parameter and return types that cphalcon does not enforce #818

Closed

Description

@niden

Problem

Zephir does not enforce a callable parameter type or a return type. For a var parameter, cphalcon has no type. At these sites phalcon throws TypeError at once. cphalcon accepts the value, and then fails later (Error or warning) or works.

zep callable parameter, phalcon callable parameter

Method cphalcon (value 'nope') phalcon
Support\Collection::each(), filter(), map(), reduce() Error: Call to undefined function nope() (an empty collection: no error) TypeError at the parameter
Container\Definition\ServiceDefinition::setFactory(), addExtender(), Container\Container::extend() Error: Call to undefined function nope() when the service is built TypeError at the parameter
Container\Resolver\Resolver::resolveCall() TypeError: Failed to create closure from callable: ... TypeError at the parameter
Container\Resolver\Lazy\LazyFactory::call() Error: Call to undefined function nope() at resolve TypeError at the parameter
DataMapper\Pdo\ConnectionLocator constructor, setRead(), setWrite() warning function "nope" not found or invalid function name, getRead() returns null TypeError at the parameter
Db\Dialect::registerCustomFunction() Error: Call to undefined function nope() when the SQL is made TypeError at the parameter
Queue subscribe() (SubscriptionConsumerTrait) TypeError from call_user_func() in consume(); the message is already removed from the queue TypeError at the parameter

zep var (no type), phalcon typed

Method phalcon type cphalcon phalcon
Forms\FormsLocator::set(), setElement() callable $factory accepts; get() gives Error: Call to undefined function nope() TypeError
Forms\FormsLocator::getElement() return callable setElement('bad', 5), getElement('bad') returns 5 TypeError
Forms\FormsLocator::get() ?object $entity get('f', 5) returns a Form TypeError
Container\Resolver\Lazy\GetCall, NewCall, StaticCall constructors Lazy|string new GetCall(5, 'm', []) works TypeError
Support\Helper\Arr\Group::__invoke() callable|string $method $method = 0 groups the rows TypeError (strict caller)

Return types that cphalcon does not enforce

Method phalcon type cphalcon phalcon
Mvc\Model\Manager::load() (used by the eager loader and getRelationRecords()) ModelInterface a relation to a class that is not a model: warning class X does not have a method "find", null TypeError: Manager::load(): Return value must be of type ModelInterface
Html\TagFactory::newInstance() object a factory that returns 5: warning first array member is not a valid class name or object, null TypeError: Return value must be of type object, int returned

Decision needed

  1. zep var: use mixed in phalcon (copy the cphalcon signature; "cphalcon loose types win").
  2. zep callable and return types: keep the phalcon type (it fails earlier, with a clear message, and the signature is the same as cphalcon), or relax it to mixed and copy the later failure.

Tests (they must run on phalcon and cphalcon with no change)

  • For each changed method: the value that is accepted by cphalcon is accepted by phalcon, and the later result is the same.

Note

Manager::load() of a class with no constructor crashes cphalcon (phalcon/cphalcon issue 1 above). Test it with a class that has a constructor.

Activity

  1. self-assigned this
    on Nov 16, 2026
  2. added
    bug
    6.0.0
    status: medium
    on Nov 16, 2026
  3. moved this to Active Sprint in Phalcon v5on Nov 16, 2026
  4. added theissue type on Nov 16, 2026
  5. added a commit that references this issue on Nov 17, 2026
  6. niden commented on Nov 17, 2026

    @niden
    SponsorMemberAuthor

    Resolved in #827

  7. moved this from Active Sprint to Implemented in Phalcon v5on Nov 17, 2026
  8. added 2 commits that reference this issue on Nov 17, 2026
  9. moved this from Implemented to Released in Phalcon v5on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

6.0.0bugstatus: medium

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions