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

PHP 8.1 Support for addPreserveText #2220

Closed
cscrewsandcaptains opened this issue Apr 28, 2022 · 0 comments · Fixed by #2239
Closed

PHP 8.1 Support for addPreserveText #2220

cscrewsandcaptains opened this issue Apr 28, 2022 · 0 comments · Fixed by #2239
Assignees
Milestone

Comments

@cscrewsandcaptains
Copy link
Contributor

cscrewsandcaptains commented Apr 28, 2022

Describe the Bug

If I use php 8.1 this code doesn't work:

Steps to Reproduce

Please provide a code sample that reproduces the issue.

<?php
require __DIR__ . '/vendor/autoload.php';

$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addTitle("test", 1);

$footer = $section->addFooter();
$footer->addPreserveText('{PAGE} / {NUMPAGES}');
	    
header("Content-Type: application/vnd.openxmlformats-officedocument.wordprocessing‌​ml.document");
header('Content-Disposition: attachment; filename=test.docx');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save("php://output");

Expected Behavior

The same output that I have if I use PHP 7.4

Current Behavior

preg_split(): Passing null to parameter #3 ($limit) of type int is deprecated
in vendor\phpoffice\phpword\src\PhpWord\Element\PreserveText.php at line 63
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
...
$matches = preg_split('/({.*?})/', $this->text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);

-> preg_split parameter #3 needs to be -1 not null.

During XMLWriter->save(...): Uncaught yii\base\ErrorException: Return type of PhpOffice\PhpWord\Shared\XMLWriter::writeAttribute($name, $value) should either be compatible with XMLWriter::writeAttribute(string $name, string $value): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in vendor\phpoffice\phpword\src\PhpWord\Shared\XMLWriter.php:174

-> add #[\ReturnTypeWillChange] attribute

Context

Please fill in your environment information:

  • PHP Version: 8.1
  • PHPWord Version: 0.18.3
@cscrewsandcaptains cscrewsandcaptains changed the title PHP 8.1 Support (createWriter and addPreserveText) PHP 8.1 Support for addPreserveText Jun 8, 2022
@Progi1984 Progi1984 added this to the v0.18.2 milestone Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants