phan / phan/phan

Dealing with extensions overriding arithmetic operators such as php-decimal

Open
#2,883 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
PHP
Stars
5.6k
Forks
365
Avg merge
1h 25m
Merged PRs (30d)
6

Description

I am working on a code base that makes heavy use of php-decimal[0].
The extension provides a new type "Decimal" which also supports arithemtic and comparion operators.
This causes Phan to issue a bunch of PhanTypeInvalid{Left|Right}OperandOf*Op.

Current Workarounds:

  1. Wrap every arithmetic operation in a new Decimal, "return new Decimal($dec1 + $dec2)"
  2. add all emitted issues types caused by Decimal to the global suppress_issue_types array.

So the question is: how would one deal with this?

  1. Is there a way to tell Phan to treat Decimal just like a regular number?
  2. What part of the source would one have to read to extend Phan to make it work with Decimal?

--
[0] http://php-decimal.io/#introduction

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file, test, or entry point is named. Start by locating Phan's checks for invalid arithmetic and comparison operands, then inspect how extension-provided Decimal types are represented; done means a documented, tested way to recognize such types without suppressing unrelated diagnostics.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.