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

Uncaught PhpOffice\PhpSpreadsheet\Exception: Spreadsheet objects cannot be json encoded in \app\ThirdParty\PHPOffice\PhpSpreadsheet\Spreadsheet.php:1519 #4079

Closed
konsoft1 opened this issue Jun 29, 2024 · 4 comments

Comments

@konsoft1
Copy link

This is:

- [v] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

I want no error execution.

What is the current behavior?


Fatal error: Uncaught PhpOffice\PhpSpreadsheet\Exception: Spreadsheet objects cannot be json encoded in E:\Work\sanarena\project\invctrlpan\app\ThirdParty\PHPOffice\PhpSpreadsheet\Spreadsheet.php:1519
Stack trace:
#0 [internal function]: PhpOffice\PhpSpreadsheet\Spreadsheet->jsonSerialize()
#1 E:\Work\sanarena\project\invctrlpan\system\Format\JSONFormatter.php(42): json_encode(Array, 960, 512)
#2 E:\Work\sanarena\project\invctrlpan\system\API\ResponseTrait.php(357): CodeIgniter\Format\JSONFormatter->format(Array)
#3 E:\Work\sanarena\project\invctrlpan\system\API\ResponseTrait.php(103): CodeIgniter\Debug\ExceptionHandler->format(Array)
#4 E:\Work\sanarena\project\invctrlpan\system\Debug\ExceptionHandler.php(83): CodeIgniter\Debug\ExceptionHandler->respond(Array, 500)
#5 E:\Work\sanarena\project\invctrlpan\system\Debug\Exceptions.php(163): CodeIgniter\Debug\ExceptionHandler->handle(Object(ReflectionException), Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), 500, 1)
#6 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(ReflectionException))
#7 {main}
thrown in E:\Work\sanarena\project\invctrlpan\app\ThirdParty\PHPOffice\PhpSpreadsheet\Spreadsheet.phpon line1519
{
"title": "ErrorException",
"type": "ErrorException",
"code": 500,
"message": "Uncaught PhpOffice\PhpSpreadsheet\Exception: Spreadsheet objects cannot be json encoded in E:\Work\sanarena\project\invctrlpan\app\ThirdParty\PHPOffice\PhpSpreadsheet\Spreadsheet.php:1519\nStack trace:\n#0 [internal function]: PhpOffice\PhpSpreadsheet\Spreadsheet->jsonSerialize()\n#1 E:\Work\sanarena\project\invctrlpan\system\Format\JSONFormatter.php(42): json_encode(Array, 960, 512)\n#2 E:\Work\sanarena\project\invctrlpan\system\API\ResponseTrait.php(357): CodeIgniter\Format\JSONFormatter->format(Array)\n#3 E:\Work\sanarena\project\invctrlpan\system\API\ResponseTrait.php(103): CodeIgniter\Debug\ExceptionHandler->format(Array)\n#4 E:\Work\sanarena\project\invctrlpan\system\Debug\ExceptionHandler.php(83): CodeIgniter\Debug\ExceptionHandler->respond(Array, 500)\n#5 E:\Work\sanarena\project\invctrlpan\system\Debug\Exceptions.php(163): CodeIgniter\Debug\ExceptionHandler->handle(Object(ReflectionException), Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), 500, 1)\n#6 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(ReflectionException))\n#7 {main}\n thrown\n【Previous Exception】\nReflectionException\nClass "Psr\SimpleCache\CacheInterface" does not exist\n#0 E:\Work\sanarena\project\invctrlpan\app\ThirdParty\PHPOffice\PhpSpreadsheet\Settings.php(147): ReflectionClass->__construct('Psr\\SimpleCache...')\n#1 E:\Work\sanarena\project\invctrlpan\app\ThirdParty\PHPOffice\PhpSpreadsheet\Settings.php(139): PhpOffice\PhpSpreadsheet\Settings::useSimpleCacheVersion3()\n#2 E:\Work\sanarena\project\invctrlpan\app\ThirdParty\PHPOffice\PhpSpreadsheet\Collection\CellsFactory.php(18): PhpOffice\PhpSpreadsheet\Settings::getCache()\n#3 E:\Work\sanarena\project\invctrlpan\app\ThirdParty\PHPOffice\PhpSpreadsheet\Worksheet\Worksheet.php(335): PhpOffice\PhpSpreadsheet\Collection\CellsFactory::getInstance(Object(PhpOffice\PhpSpreadsheet\Worksheet\Worksheet))\n#4 E:\Work\sanarena\project\invctrlpan\app\ThirdParty\PHPOffice\PhpSpreadsheet\Spreadsheet.php(409): PhpOffice\PhpSpreadsheet\Worksheet\Worksheet->__construct(Object(PhpOffice\PhpSpreadsheet\Spreadsheet))\n#5 E:\Work\sanarena\project\invctrlpan\app\Controllers\Document\Download.php(151): PhpOffice\PhpSpreadsheet\Spreadsheet->__construct()\n#6 E:\Work\sanarena\project\invctrlpan\system\CodeIgniter.php(933): App\Controllers\Document\Download->getExportXml('8')\n#7 E:\Work\sanarena\project\invctrlpan\system\CodeIgniter.php(509): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\Document\Download))\n#8 E:\Work\sanarena\project\invctrlpan\system\CodeIgniter.php(355): CodeIgniter\CodeIgniter->handleRequest(NULL, Object(Config\Cache), false)\n#9 E:\Work\sanarena\project\invctrlpan\system\Boot.php(325): CodeIgniter\CodeIgniter->run()\n#10 E:\Work\sanarena\project\invctrlpan\system\Boot.php(67): CodeIgniter\Boot::runCodeIgniter(Object(CodeIgniter\CodeIgniter))\n#11 E:\Work\sanarena\project\invctrlpan\public\index.php(56): CodeIgniter\Boot::bootWeb(Object(Config\Paths))\n#12 {main}",
"file": "E:\Work\sanarena\project\invctrlpan\app\ThirdParty\PHPOffice\PhpSpreadsheet\Spreadsheet.php",
"line": 1519,
"trace": [
{
"function": "shutdownHandler",
"class": "CodeIgniter\Debug\Exceptions",
"type": "->",
"args": []
}
]
}

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

// CodeIgniter code
namespace App\Controllers\Document;

use App\Controllers\BaseController;
use PhpOffice\PhpSpreadsheet\Spreadsheet;

class Download extends BaseController
{
    public function getExportXml($doc_id) {

// add code that show the issue here...
        $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

// rest of the file
        return 'success';
    }
}

If this is an issue with reading a specific spreadsheet file, then it may be appropriate to provide a sample file that demonstrates the problem; but please keep it as small as possible, and sanitize any confidential information before uploading.

### What features do you think are causing the issue

PhpSpreadsheet.php file itself

### Does an issue affect all spreadsheet file formats? If not, which formats are affected?
Yes, I cannot even create an PhpSpreadsheet Object.

### Which versions of PhpSpreadsheet and PHP are affected?
PhpSpreadsheet 2.1.0
PHP 8.2.12
@oleibman
Copy link
Collaborator

Behavior is deliberate - Spreadsheet objects cannot be serialized or json encoded. See PR #3199.

@konsoft1
Copy link
Author

But I never serialized or json encoded the Spreadsheet object. I just created the object.

@oleibman
Copy link
Collaborator

Something is calling json_encode. But it is not called anywhere inside PhpSpreadsheet. I see the following external JSON calls in your stack trace.

#1 E:\Work\sanarena\project\invctrlpan\system\Format\JSONFormatter.php(42): json_encode(Array, 960, 512)
#2 E:\Work\sanarena\project\invctrlpan\system\API\ResponseTrait.php(357): CodeIgniter\Format\JSONFormatter->format(Array)

Is it possible that you have a Spreadsheet object in your array when this code is invoked?

@oleibman
Copy link
Collaborator

oleibman commented Oct 7, 2024

Closing. No response in over 3 months.

@oleibman oleibman closed this as completed Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants