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

Undefined offset error when object is casted to array and has string keys #1677

Closed
redelschaap opened this issue Mar 27, 2018 · 3 comments
Closed

Comments

@redelschaap
Copy link
Contributor

Summary of problem or feature request

I get an error "Undefined offset" when an object is used to generate the data tables when that object is casted to an array and uses string keys. It turns out that in this case, keys are not usable to get a value from the casted array as stated here: https://stackoverflow.com/a/11353855/1997303. While this behaviour is odd, it seems expected: http://www.php.net/language.types.array.php#language.types.array.casting.

More details about the exception:

ErrorException

Undefined offset: 48738%0A
--
in Helper.php (line 233)
at HandleExceptions->handleError(8, 'Undefined offset: 48738', 'vendor/yajra/laravel-datatables-oracle/src/Helper.php', 233, array('row' => object(stdClass), 'data' => array('1', '1'), 'key' => '48738'))in Helper.php (line 233)
at Helper::convertToArray(object(stdClass))in Helper.php (line 227)
at Helper::convertToArray(object(stdClass))in Helper.php (line 227)
at Helper::convertToArray(array(object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass)))in Helper.php (line 227)
at Helper::convertToArray(object(stdClass))in Helper.php (line 227)
at Helper::convertToArray(object(Order))in DataProcessor.php (line 96)
at DataProcessor->process(true)in BaseEngine.php (line 739)
at BaseEngine->getProcessedData(true)in BaseEngine.php (line 686)
at BaseEngine->render(true)in BaseEngine.php (line 599)
at BaseEngine->make(true, true)in CollectionEngine.php (line 242)
at CollectionEngine->make(true)in OrderController.php (line 33)
at OrderController->datatables()
at call_user_func_array(array(object(OrderController), 'datatables'), array())in Controller.php (line 55)
at Controller->callAction('datatables', array())in ControllerDispatcher.php (line 44)
at ControllerDispatcher->dispatch(object(Route), object(OrderController), 'datatables')in Route.php (line 203)
at Route->runController()in Route.php (line 160)
at Route->run()in Router.php (line 572)
at Router->Illuminate\Routing\{closure}(object(Request))in Pipeline.php (line 30)
at Pipeline->Illuminate\Routing\{closure}(object(Request))in SubstituteBindings.php (line 41)
at SubstituteBindings->handle(object(Request), object(Closure))in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))in Authenticate.php (line 43)
at Authenticate->handle(object(Request), object(Closure))in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))in VerifyCsrfToken.php (line 65)
at VerifyCsrfToken->handle(object(Request), object(Closure))in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))in ShareErrorsFromSession.php (line 49)
at ShareErrorsFromSession->handle(object(Request), object(Closure))in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))in StartSession.php (line 64)
at StartSession->handle(object(Request), object(Closure))in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))in AddQueuedCookiesToResponse.php (line 37)
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))in EncryptCookies.php (line 59)
at EncryptCookies->handle(object(Request), object(Closure))in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))in Pipeline.php (line 102)
at Pipeline->then(object(Closure))in Router.php (line 574)
at Router->runRouteWithinStack(object(Route), object(Request))in Router.php (line 533)
at Router->dispatchToRoute(object(Request))in Router.php (line 511)
at Router->dispatch(object(Request))in Kernel.php (line 176)
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))in Pipeline.php (line 30)
at Pipeline->Illuminate\Routing\{closure}(object(Request))in CheckForMaintenanceMode.php (line 46)
at CheckForMaintenanceMode->handle(object(Request), object(Closure))in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))in Pipeline.php (line 102)
at Pipeline->then(object(Closure))in Kernel.php (line 151)
at Kernel->sendRequestThroughRouter(object(Request))in Kernel.php (line 116)
at Kernel->handle(object(Request))in index.php (line 53)

Solution

I fixed this with a foreach loop.

Fix for 7.0: #1674
Fix for 6.0: #1675
Fix for 5.0: #1676

@yajra
Copy link
Owner

yajra commented Mar 28, 2018

Thanks for the PRs. Can you please provide some snippets to reproduce the issue?

@redelschaap
Copy link
Contributor Author

In fact I cannot. We only saw this behaviour after using datatables after a while and in a grid with 350+ records, specific to one record only. The data in that record was comparable with data from other records, so it seems to happen only occasionally and not with every Laravel model / datatables record. When I did some research online, more people see this odd behaviour only in some situations, so it's not really predictable.

The code changes in my PRs result in the same outcome as the original code, but prevents these odd errors.

@redelschaap
Copy link
Contributor Author

Issue fixed for v6, v7 and v8.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants