laravelMp3
laravelMp3 copied to clipboard
Laravel Container Returns Same Instance - Causing ALL Calls to Return Same Info
"packages": [
{
"name": "acekyd/laravelmp3",
"version": "1.0.3",
"source": {
"type": "git",
"url": "https://github.com/acekyd/laravelMp3.git",
"reference": "28a870499a489fe7da8ce84aba2ffa62903a4d68"
},
Consider:
Route::get('/me', function () {
$mp3 = resolve(\Acekyd\LaravelMP3\LaravelMP3::class);
dump($mp3->getDuration('C:\laragon\webroots\www\backpack\2.mp3'));
dump($bar->getDuration('C:\laragon\webroots\www\backpack\1.mp3'));
});
This gets:
2:09
2:09
But 2.mp3 is 2.09 seconds and 1.mp3 is 0:03 seconds. Switching them around has the same effect.
But if one does:
Route::get('/me', function () {
//dump(LaravelMP3::getDuration('C:\laragon\webroots\www\backpack\2.mp3'));
//dump(LaravelMP3::getDuration('C:\laragon\webroots\www\backpack\1.mp3'));
$mp3 = resolve(\Acekyd\LaravelMP3\LaravelMP3::class);
dump($mp3->getDuration('C:\laragon\webroots\www\backpack\2.mp3'));
$bar = resolve(\Acekyd\LaravelMP3\LaravelMP3::class);
dump($mp3->getDuration('C:\laragon\webroots\www\backpack\1.mp3'));
});
/*
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)
Cannot declare class getid3_exception, because the name is already in use
*/
So, resolving this twice per request fails.
I can reproduce all of this using a simple test file:
<?php
require_once('./vendor/autoload.php');
use Acekyd\LaravelMP3\LaravelMP3;
$it = new LaravelMP3();
foreach (["1.mp3", "2.mp3"] as $file) {
dump($it->getDuration($file));
}
The above says that BOTH files are 0:03 seconds duration (but 2.mp3 is 2:09 seconds).
<?php
require_once('./vendor/autoload.php');
use Acekyd\LaravelMP3\LaravelMP3;
foreach (["1.mp3", "2.mp3"] as $file) {
$it = new LaravelMP3();
dump($it->getDuration($file));
}
Throws these errors:
C:\laragon\webroots\www\backpack>php test.php
"00:03"
Fatal error: Uncaught Error: Cannot access private property Acekyd\LaravelMP3\LaravelMP3::$info in C:\laragon\webroots\www\backpack\test.php:10
Stack trace:
#0 {main}
thrown in C:\laragon\webroots\www\backpack\test.php on line 10
C:\laragon\webroots\www\backpack>php test.php
"00:03"
Fatal error: Cannot declare class getid3_exception, because the name is already in use in C:\laragon\
It's not likely that a cache is being used - it's more likely that there is a SINGLE instance of Acekyd\LaravelMP3\LaravelMP3 in existence throughout a single request and that is always returning the first file fetched.
The class redeclaration has been fixed in latest master BTW.
#2 is a proposed solution.
is this > include_once('getid3/getid3.php'); the solution?