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

fix(compiler): Provide empty string instead of null value #600

Open
wants to merge 2 commits into
base: support/3.1
Choose a base branch
from

Conversation

Hipska
Copy link
Contributor

@Hipska Hipska commented Jan 8, 2024

To reproduce

Having :

  • an iTop 3.1 clone
  • PHP 8.1+
  • php notices enabled

Deploy this XML, that is redefining a dict key to an empty value :

<?xml version="1.0" encoding="UTF-8"?>
<itop_design version="1.7">
  <dictionaries>
    <dictionary id="EN US" _delta="must_exist">
      <entries>
        <entry id="Class:UserRequest/Attribute:urgency" _delta="force"></entry>
      </entries>
    </dictionary>
  </dictionaries>
</itop_design>

Upon compilation (either by the setup or the toolkit) you'll get the following notices :

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in C:\Dev\wamp64\www\itop-31\setup\compiler.class.inc.php on line 3272

Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in C:\Dev\wamp64\www\itop-31\setup\compiler.class.inc.php on line 1170

They are blocking during setup.

Analysis

The methods FilterDictString and QuoteForPHP both use strpos or str_replace who give a deprecation notice when the argument is null:

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /var/www/html/setup/compiler.class.inc.php on line 3231
Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/html/setup/compiler.class.inc.php on line 1146

This message is repeated for each empty dictionary item, which seems to happen on a Professional instance connected to the Designer.

Logs taken from a iTop Professional 3.1.0-3. The null argument gives a deprecation notice since PHP 8.1, which is supported for this iTop version.

@Hipska Hipska changed the base branch from develop to support/3.1 January 8, 2024 12:34
@piRGoif piRGoif self-assigned this Jan 10, 2024
@piRGoif piRGoif added the bug Something isn't working label Jan 10, 2024
@piRGoif
Copy link
Contributor

piRGoif commented Jan 10, 2024

Hello Thomas,
Can you provide some sample dict keys to reproduce the issue ?

@Hipska
Copy link
Contributor Author

Hipska commented Jan 11, 2024

I guess it is just <entry id="dict:code"/>.

@Hipska
Copy link
Contributor Author

Hipska commented Feb 2, 2024

Other PHP 8.1 findings:

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/core/ormcaselog.class.inc.php on line 172
Deprecated: md5(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/core/ormdocument.class.inc.php on line 346

@piRGoif
Copy link
Contributor

piRGoif commented Feb 2, 2024

Hello,
Thanks for the 2 other deprecated notices on PHP 8.1, I've created N°7212
Can you detail how to reproduce them, especially the one on ormDocument ?

@Hipska
Copy link
Contributor Author

Hipska commented Feb 2, 2024

Already discussed with @Molkobain on Slack.

Displaying a Person on the portal (e.g. click on manager on profile page) causes the ormDocument notice.

The other one was when going to a User's details page (might be related to having the activity panel open)

@piRGoif
Copy link
Contributor

piRGoif commented Feb 2, 2024

ormCaselog error is handled in #607

@Hipska
Copy link
Contributor Author

Hipska commented Mar 6, 2024

Having this issue as well with 3.1.1:

Deprecated:  strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /var/www/html/setup/compiler.class.inc.php on line 3264
Deprecated:  str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/html/setup/compiler.class.inc.php on line 1170

This is becoming a major issue since it blocks the setup while upgrading to 3.1.1 when for example the sv-display-mgmt is installed.

@Hipska
Copy link
Contributor Author

Hipska commented Mar 6, 2024

Even replacing this line with the following isn't a suitable workaround:

<entry id="Class:Display/Attribute:type_id+" _delta="define"></entry>

Looks like there is no way anymore to define an empty dict in xml !!!

Hipska added a commit to Super-Visions/sv-display-mgmt that referenced this pull request Mar 6, 2024
This to workaround the bug mentioned in Combodo/iTop#600
@piRGoif
Copy link
Contributor

piRGoif commented Mar 7, 2024

Woops absolutely sorry I forgot this PR :(
I've just tried to reproduce on a standard support/3.1 clone, and I got it !
I'll rewrite the description a little, and send the PR back for review.

@piRGoif piRGoif added the Setup Related to the setup process (install / upgrade) label Mar 7, 2024
@piRGoif
Copy link
Contributor

piRGoif commented Mar 7, 2024

@Molkobain will be the new assignee for the reviews next month.

@piRGoif piRGoif assigned Molkobain and unassigned piRGoif Mar 7, 2024
Copy link
Member

@Molkobain Molkobain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technical review: We would rather fix the root cause than the symptom:

  • FilterDictString()
    • Method type hinting can be enforce as it is only used within the compiler: FilterDictString(string $s): string
    • Fix te one usage in the line below your proposal: self::FilterDictString($sValue ?? '')
  • QuoteForPHP()
    • As it is used in many places, fix its internal usages with $s = $s ?? ''; at the begining of the method.

@Hipska Hipska requested a review from Molkobain May 3, 2024 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Setup Related to the setup process (install / upgrade)
Projects
Status: Pending functional review
3 participants