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

Fixed PHP 8.2 deprecation warnings: 'creation of dynamic property'. #1

Conversation

hostep
Copy link
Contributor

@hostep hostep commented May 22, 2023

Fixes deprecation warnings with PHP 8.2: Creation of dynamic property xxx is deprecated

Found with phpstan:

  1. Have latest version of phpstan installed somewhere (I've used version 1.10.15)
  2. Clone this repo
  3. Inside the repo, run:
$ /path/to/phpstan analyse --level=0 . | grep 'Access to an undefined property'
  1. Expected to see no errors, but seeing:
  331    Access to an undefined property Zend_Pdf::$_pdfHeaderVersion.
  377    Access to an undefined property Zend_Pdf::$_pdfHeaderVersion.
  410    Access to an undefined property Zend_Pdf_Action::$childOutlines.
  80     Access to an undefined property Zend_Pdf_Canvas::$_procset.
  277    Access to an undefined property Zend_Pdf_Canvas_Abstract::$_dictionary.
  136    Access to an undefined property Zend_Pdf_Element::$value.
  158    Access to an undefined property Zend_Pdf_Outline::$_title.
  160    Access to an undefined property Zend_Pdf_Outline::$_color.
  161    Access to an undefined property Zend_Pdf_Outline::$_italic.
  162    Access to an undefined property Zend_Pdf_Outline::$_bold.
  163    Access to an undefined property Zend_Pdf_Outline::$_target.
  102    Access to an undefined property Zend_Pdf_Resource_Font_CidFont::$_isMonospaced.
  64     Access to an undefined property Zend_Pdf_Resource_Font_Simple_Parsed::$_isMonospaced.
  100    Access to an undefined property Zend_Pdf_Resource_Font_Simple_Standard_Courier::$_isMonospaced.
  101    Access to an undefined property Zend_Pdf_Resource_Font_Simple_Standard_CourierBold::$_isMonospaced.
  102    Access to an undefined property Zend_Pdf_Resource_Font_Simple_Standard_CourierBoldOblique::$_isMonospaced.
  102    Access to an undefined property Zend_Pdf_Resource_Font_Simple_Standard_CourierOblique::$_isMonospaced.
  110    Access to an undefined property Zend_Pdf_Resource_Font_Simple_Standard_Helvetica::$_isMonospaced.
  110    Access to an undefined property Zend_Pdf_Resource_Font_Simple_Standard_HelveticaBold::$_isMonospaced.
  113    Access to an undefined property Zend_Pdf_Resource_Font_Simple_Standard_HelveticaBoldOblique::$_isMonospaced.
  112    Access to an undefined property Zend_Pdf_Resource_Font_Simple_Standard_HelveticaOblique::$_isMonospaced.
  230    Access to an undefined property Zend_Pdf_Resource_Font_Simple_Standard_Symbol::$_isMonospaced.
  109    Access to an undefined property Zend_Pdf_Resource_Font_Simple_Standard_TimesBold::$_isMonospaced.
  110    Access to an undefined property Zend_Pdf_Resource_Font_Simple_Standard_TimesBoldItalic::$_isMonospaced.
  110    Access to an undefined property Zend_Pdf_Resource_Font_Simple_Standard_TimesItalic::$_isMonospaced.
  110    Access to an undefined property Zend_Pdf_Resource_Font_Simple_Standard_TimesRoman::$_isMonospaced.
  250    Access to an undefined property Zend_Pdf_Resource_Font_Simple_Standard_ZapfDingbats::$_isMonospaced.
  121    Access to an undefined property Zend_Pdf_Resource_Font_Type0::$_isMonospaced.
  1. Extra way of testing (not very thouroughly), run inside this repo:
$ composer install
  1. Create a file test.php inside the repo with this contents:
<?php

error_reporting(-1);

require_once('vendor/autoload.php');

// test for _isMonospaced problems
\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_COURIER);
\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_COURIER_BOLD);
\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_COURIER_OBLIQUE);
\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_COURIER_ITALIC);
\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_COURIER_BOLD_OBLIQUE);
\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_COURIER_BOLD_ITALIC);
\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA);
\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA_BOLD);
\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA_OBLIQUE);
\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA_ITALIC);
\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA_BOLD_OBLIQUE);
\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA_BOLD_ITALIC);
\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_SYMBOL);
\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_TIMES_ROMAN);
\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_TIMES);
\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_TIMES_BOLD);
\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_TIMES_ITALIC);
\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_TIMES_BOLD_ITALIC);
\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_ZAPFDINGBATS);

// test for Zend_Pdf problems
new \Zend_Pdf();

// test for Zend_Pdf_Canvas problems
(new \Zend_Pdf_Canvas(100, 100))->setLineWidth(10);

// test for Zend_Pdf_Outline
(new \Zend_Pdf_Outline_Created(['title' => 'test title']))->getOptions();

// tests for Zend_Pdf_Element
var_dump((new \Zend_Pdf_Element_Boolean(true))->toPhp());
var_dump((new \Zend_Pdf_Element_Name('test name'))->toPhp());
var_dump((new \Zend_Pdf_Element_Null())->toPhp());
var_dump((new \Zend_Pdf_Element_Numeric(123))->toPhp());
var_dump((new \Zend_Pdf_Element_Stream('test stream'))->toPhp());
var_dump((new \Zend_Pdf_Element_String('test string'))->toPhp());

// tests for Zend_Pdf_Canvas_Abstract
(new \Zend_Pdf_Page(100, 200))->setStyle(new \Zend_Pdf_Style());
  1. Execute the test.php file using php 8.2 on the command line, expected is to get no deprecation warnings and no new errors after merging this PR.

PR fixes:

  • typo's in member names
  • wrong member name used
  • moves members from lower classes to classes which they extend from

This fixes about half of the warnings mentioned in https://github.com/magento/adobe-commerce-beta/issues/61, If I find more time and this PR actually gets approved, I might try to tackle the others as well one day.

@sidolov
Copy link
Contributor

sidolov commented Jul 19, 2023

@hostep thanks for the fixes you provided! Do you want to continue work on this PR to fix all warnings or do you feel we can proceed with delivery and fix the rest of them in the next PR?

@hostep
Copy link
Contributor Author

hostep commented Jul 19, 2023

@sidolov: see an overview of all PR's that are related to the same issues over here: magento/magento2#37573

I think everything is solved with those 5 PR's.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants