Skip to content

Illegal string offset warning in PHP 7 #927

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

Closed
likeuntomurphy opened this issue Oct 29, 2016 · 16 comments
Closed

Illegal string offset warning in PHP 7 #927

likeuntomurphy opened this issue Oct 29, 2016 · 16 comments

Comments

@likeuntomurphy
Copy link
Contributor

Saving a document triggers an Illegal string offset 'w:compatSetting' warning, because $this->settings['w:compat'] is initialized as an empty string instead of an empty array in src/PhpWord/Writer/Word2007/Part/Settings.php. This appears to be the case with PHP7 — PHP5 does not raise the warning.

Progi1984 added a commit that referenced this issue Dec 13, 2016
Krosh pushed a commit to Krosh/PHPWord that referenced this issue Dec 28, 2016
@germansokolov13
Copy link

I've just downloaded PHPWord 0.13.0 via Composer and it's still an empty string instead of an empty array there. Not merged into a release?

@philwu
Copy link

philwu commented Mar 7, 2017

I've just downloaded PHPWord 0.13.0 via Composer still get the problem.
Win10 build 14393+IIS
PHP 7.1.1

@thibaultvanc
Copy link

thibaultvanc commented Mar 13, 2017

had same error on PHP 7.1.2 BUT :

try {
      $objWriter->save($path);

    } catch (Exception $e) {

    }
    return redirect('/'.$path);

WORK FOR ME

@shad0wfir3
Copy link

@thibaultvanc can you expand on where you implemented this? currently getting the same error on php 7.1.2

@DevSazal
Copy link

Doc file created successfully
but why this message is showing....

Warning: Illegal string offset 'w:compatSetting' in C:\xampp\htdocs\greek\vendor\phpoffice\phpword\src\PhpWord\Writer\Word2007\Part\Settings.php on line 173

Notice: Array to string conversion in C:\xampp\htdocs\greek\vendor\phpoffice\phpword\src\PhpWord\Writer\Word2007\Part\Settings.php on line 173

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\greek\vendor\phpoffice\phpword\src\PhpWord\Writer\Word2007\Part\Settings.php on line 80

@wqj97
Copy link

wqj97 commented Apr 14, 2017

Still have problem today

@Jaspur
Copy link

Jaspur commented Apr 14, 2017

Same issue here. PHP 7.1.3

@likeuntomurphy
Copy link
Contributor Author

This has been merged into the develop branch and is slated for inclusion in v0.14.0. However, the release is on hold indefinitely because the project does not have an active maintainer.

Your best bet is to fork the develop branch or apply the patch to your local copy.

@Jaspur
Copy link

Jaspur commented May 4, 2017

Still, when I add this in composer.json:

"phpoffice/phpword": "dev-master",

And run this (word.patch is a file with content of the patch from the commit above):

git apply --stat word.patch

It still returns the error:

Illegal string offset 'w:compatSetting'

@likeuntomurphy

@likeuntomurphy
Copy link
Contributor Author

Ok, try composer require phpoffice/phpword:dev-develop — that should do it once for all:

$ composer require phpoffice/phpword:dev-develop
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Updating phpoffice/phpword (dev-master 0a3f873 => dev-develop 4decaff):  Checking out 4decaffd53

There are still many things I don’t know about composer, and I didn't realize this would work.

@juanwilde
Copy link

dev-develop did the trick! Now it's time to wait for 0.14 release

@Alexmg86
Copy link
Contributor

000e36a

eddturtle pushed a commit to eddturtle/PHPWord that referenced this issue Jul 10, 2017
@maulik37
Copy link

this is work fine for me
https://stackoverflow.com/questions/46202824/how-to-fix-warning-illegal-string-offset-in-laravel-5-4/46482346#46482346

@carlosmolano
Copy link

carlosmolano commented Nov 30, 2017

Change en file...

PHPOffice\PHPWord\Writer\Word2007\Part\Settings

private function getSettings()
{
.......

        'w:compat' => ' ',

       ........
}

Updated to

private function getSettings()
{
.......

        'w:compat' => array('@attributes' => array('w:val' => '')),

       ........
}

@germansokolov13
Copy link

Times change, generations replace each other. And they still fight their formidable foe. The two single quotes keep the upper hand in the php-development battle.

@fauzannoorazhar
Copy link

Change en file...

PHPOffice\PHPWord\Writer\Word2007\Part\Settings

private function getSettings()
{
.......

        'w:compat' => ' ',

       ........
}

Updated to

private function getSettings()
{
.......

        'w:compat' => array('@attributes' => array('w:val' => '')),

       ........
}

its work for me, thanks

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