Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sfCoreAutoload::make() doesn't work #378

Open
JohannesTyra opened this issue Dec 5, 2024 · 8 comments
Open

sfCoreAutoload::make() doesn't work #378

JohannesTyra opened this issue Dec 5, 2024 · 8 comments

Comments

@JohannesTyra
Copy link

Hey Team,
the sfCoreAutoload::make() doesn't work.

https://github.com/FriendsOfSymfony1/symfony1/blob/master/lib/autoload/sfCoreAutoload.class.php

The preg_replace needs the "old PHP array syntax":
preg_replace('/protected \$classes = array *\(.*?\);/s',

In the code the new syntax protected $classes = [***] is used - without array.
So the preg_replace fails.


Using

    protected $classes = array(
    'sfaction' => 'action/sfAction.class.php',
    'sfactionstack' => 'action/sfActionStack.class.php',
    'sfactionstackentry' => 'action/sfActionStackEntry.class.php',

fixes it.


Thx for support.

@JohannesTyra
Copy link
Author

@JohannesTyra
Copy link
Author

Otherwise this pattern will fix it also:

'/protected \$classes = (array|\\[) *\(.*?\);/s'

This matches both array(...) and [...] declarations.

@vendethiel
Copy link

Doesn’t the end part ()) also need to be fixed?

@JohannesTyra
Copy link
Author

JohannesTyra commented Dec 5, 2024

@vendethiel You are right.

This code works for both declarations and using the new style in the replace.

$content = preg_replace('/protected \$classes = (array|\\[) *(.*?);/s', sprintf("protected \$classes = [\n%s ];", $classes), file_get_contents(__FILE__));

@thePanz
Copy link
Member

thePanz commented Dec 10, 2024

@JohannesTyra @vendethiel thanks for the report! I was using the latest release of SF1, but did not get the error.
Can you help me to reproduce it? Thanks!

@JohannesTyra
Copy link
Author

@thePanz Which declaration you have in the latest relaese?

53a2b12#diff-eaebe010ea1054743688dffd43445400da8d71e461475fbd0910c23f4a4dbc63

... array() OR [] ?

The preg_replace works only on the array() syntax.

@thePanz
Copy link
Member

thePanz commented Dec 10, 2024

the latest release uses the short array syntax.

How can I reproduce the error?

@JohannesTyra
Copy link
Author

Try to call sfCoreAutoload::make() .. the function uses the old array syntax (not short).
So it does not match.

I build up a custom task for this.

<?php

class sfAutoloadTestTask extends sfBaseTask
{
  protected function configure()
  {
    $this->namespace = 'test';
    $this->name = 'autoload';
    $this->briefDescription = 'Tests sfCoreAutoload::make() functionality';

    // Optionally, add arguments or options if needed
  }

  protected function execute($arguments = array(), $options = array())
  {
    // Call sfCoreAutoload::make()
    sfCoreAutoload::make();

    // Check if autoloading works
    if (class_exists('sfCoreAutoload')) {
      $this->logSection('autoload', 'Autoloading is initialized and sfCoreAutoload is available.');
    } else {
      $this->logSection('autoload', 'Autoloading failed.');
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants