function ereg deprecated, how to update to preg_match?: - preg-match

I'm using an old php script that runs on php 5.2 but host no longer provides php below 5.4
I'm getting an error regarding function ereg that needs to be updated to preg_match but I have no idea how this is done and a look around the web isn't too helpful. Any help available?
Existing code:
if (!ereg('^/[^./][^/]/*$', $cfg["theme"]))

You may use
if (!preg_match('~^/[^./][^/]/*$~', $cfg["theme"]))
Pay attention to the regex delimiter, here, ~.

Related

i cant run php artisan make:controller FallbackController

It gives me this error
ArgumentCountError
Too few arguments to function Illuminate\Routing\Router::fallback(), 0 passed in C:\xampp\htdocs\gmvcc\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 338 and exactly 1 expected
im using laravel 9.
I suggest a combination of suggested places to check, based on the provided error response you pasted above:
First, check your web.php or api.php in routes folder and verify if you have unexpected additional parameters. For example, Route::post('/foo/{hello}/bar/{world}', [FallbackController::class, 'testFunction']); and we see that you'll next have to declared $hello and $world shortly.
Next, does your function looks like this? (following the example from #1) Such as public function testFunction($hello, $world, Request $request).
Third, based on the HTTP method used, and for the route defined using FallbackController, were you able to simplify it to test your HTTP method with the route again? For this, I still assume it is a route in api.php correct?
Lastly, if any of above fails to help, I recommend implementing a simple route to test with (GET or POST) first. This will help you trace back what you missed.
Using Docker (and a fresh Laravel 9) to help fill in other clues, like incorrect php or composer version and more - using a template like this might help, https://github.com/k90mirzaei/laravel9-docker.
Please note, I am answering based on the provided error first. Hope my checklist above helps.

Laravel 8 project is giving serialize error

When I use the php artisan serve command, the project gives the following error.
Laravel\SerializableClosure\Exceptions\InvalidSignatureException Your
serialized closure might have been modified or it's unsafe to be
unserialized.
What is the reason for that? How can I solve this?
I also had similar type of issue like this as shown in attached image and I was able to resolve that by referring this article. check this article clearly

Laravel's pretty var_dump(), dd(), not working anymore

For some reason laravel's dd() function decided to stop functioning. I have no idea how this happened. I tried composer update already but I'm not sure what else can be going on. The debug key is set to true in the config.
Where should I look to solve this problem? I'm using Laravel 4.2.16
NOTE:
dd() now simply functions as var_dump(), it doesn't prettify it anymore
Solved it. I loaded my vagrant machine with the wrong config and was running hhvm instead of regular php-fpm. Hence xdebug, which handles the pretty dd(), was not being loaded. I reloaded my box with the correct settings (without hhvm and hack) and everything started working again
Is dd the only Laravel helper function that doesn't work? If not then check the contents of vendor/composer/autoload_files.php. The laravel support helpers are loaded here. If the other helper functions are fine you can check the contents of laravel/framework/src/Illuminate/Support/helpers.php to see what's going on - this is where the function is created.

Syntax error from older PHP script

Can someone please tell me what the error is in the following script? Was forced to update to php 5.3 instead of 4 and now site is down
<!--form action : <?=//MYSURL_DEV?>properties_features.php-->
You should check your php.ini to see if short tags are enabled. They are often disabled by default. As of PHP 5.4 short tags are always on, but not so on PHP 5.3 and lower.
If you're able, in php.ini you'd enable this with:
short_open_tag = On
Be aware thought that in some hosting environments you actually may be prevented from enabling the use of short tags. And even though 5.4 has them always available, they are generally not recommended because of the very issue that you may have encountered: you may move to another environment that doesn't have them enabled (or even allow it).
The alternative is to use:
<?php echo $var; ?>
More info can be found here: Are PHP short tags acceptable to use?

Error when logging to Magento connect manager

I am getting the following error when I log into Magento connect Manager.
Exception caught:
Unknown error (8192): Function eregi() is deprecated in /home/nirmal/public_html/magento/downloader/pearlib/php/PEAR/Registry.php on line 774
The php version I am using is 5.3. Can you help me?
Hmm, this is tricky. This is a so-called E_DEPRECATED notice, pointing out a function call that still works, but will be removed in one of the coming versions of PHP.
You could manually edit the code to fix this, but it seems to be in a core part of Magento or the PEAR client. It is likely to be fixed in a future version of Magento. Turning off error reporting for E_DEPRECATED notices might be justified in this case.
The error_reporting setting for that would be
error_reporting(E_ALL ^ E_DEPRECATED);
This is because eregi() function is deprecated
Warning
This function has been DEPRECATED as
of PHP 5.3.0. Relying on this feature
is highly discouraged.
http://php.net/manual/en/function.ereg.php
Here is a fix of this problem
http://www.devcomments.com/magento-and-deprecated-errors-solved-to290776.htm
Here is also a very similar issue and fix. Take a look here
http://www.magentocommerce.com/boards/viewthread/59208/
The core of this problem is that Magento still doesn't officially support the PHP 5.3 branch as far as I am aware. Since the framework catches even quasi-serious errors and kills execution, you may discover many such bugs.
The easy fix is to use the current 5.2.X version of PHP.

Resources