Skip to content

Conversation

@ddevsr
Copy link
Collaborator

@ddevsr ddevsr commented Aug 25, 2023

Description
See #7859 (Comment).

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added bug Verified issues on the current code behavior or pull requests that will fix them 4.4 labels Aug 25, 2023
@MGatner
Copy link
Member

MGatner commented Aug 26, 2023

@kenjis seemed to be proposing an alternate fix:

If it is possible, I would like to use new DocTypes().

@paulbalandan
Copy link
Member

I would also like new DocTypes. In our unreleased (yet) phpstan extension, config(DocTypes::class) would be flagged.

@kenjis
Copy link
Member

kenjis commented Aug 29, 2023

<?php

namespace App\Controllers;

use Config\DocTypes;

class Home extends BaseController
{
    public function index(): string
    {
        $iterator = new \CodeIgniter\Debug\Iterator();

        $iterator->add('config()', static function () {
            $config = config(DocTypes::class);
        });
        $iterator->add('new', static function () {
            $config = new DocTypes();
        });

        return $iterator->run(300000);
    }
}
Test Time Memory
config() 0.2692 0 Bytes
new 0.0278 0 Bytes
$ php -v
PHP 8.1.2-1ubuntu2.13 (cli) (built: Jun 28 2023 14:01:49) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2-1ubuntu2.13, Copyright (c), by Zend Technologies

@kenjis
Copy link
Member

kenjis commented Aug 29, 2023

@ddevsr Do you really need to share the instance with Factories?

@kenjis
Copy link
Member

kenjis commented Aug 29, 2023

@ddevsr Can you try #7872 ?

@ddevsr
Copy link
Collaborator Author

ddevsr commented Aug 29, 2023

@kenjis I have tried, same result undefined method Config\DocTypes::__set_state

image
image
image
image

@kenjis
Copy link
Member

kenjis commented Aug 29, 2023

@ddevsr Please clear the cache.

@ddevsr
Copy link
Collaborator Author

ddevsr commented Aug 29, 2023

@kenjis Oh, sorry. I can confirm works

@ddevsr ddevsr closed this Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants