Skip to content

Update the PHP samples to xrpl_php 2.x - #3881

Open
AlexanderBuzz wants to merge 1 commit into
XRPLF:masterfrom
AlexanderBuzz:docs/update-php-samples
Open

Update the PHP samples to xrpl_php 2.x#3881
AlexanderBuzz wants to merge 1 commit into
XRPLF:masterfrom
AlexanderBuzz:docs/update-php-samples

Conversation

@AlexanderBuzz

Copy link
Copy Markdown
Contributor

The XRPL_PHP library has been updated and the PHP code samples don't run with the newest version.
They use the namespace XRPL_PHP\, but the library renamed it to Hardcastle\XRPL_PHP\

The samples' own composer.json pins ^0.8.5, so they are internally
consistent — but Get Started Using PHP tells the reader:

composer require hardcastle/xrpl_php

That is unpinned, so anyone following the tutorial today installs 2.3.0 and every sample fails immediately:

PHP Fatal error: Uncaught Error: Class "XRPL_PHP\Client\JsonRpcClient" not found

Changes

  • Namespace corrected in the three samples and in the inline code blocks of
    both tutorials — 20 places. send-xrp.md pulls most of its code in via
    code-snippet, so only its three additional inline blocks needed touching.
  • composer.json of both samples: ^0.8.5 → ^2.3. Pinning the tutorial
    to 0.8.5 instead would also have worked, but that release predates everything
    from 1.0.0 onwards.
  • Requirements in get-started-php.md: the page says PHP 8.1. The library
    has required 8.2 since 1.0.0 and declares it as a constraint since 2.0.0, so
    8.1 can no longer install it. ext-bcmath was missing from the list as well —
    it is a direct requirement alongside GMP.
  • A stale comment in send-xrp.php named an address that does not belong to
    the seed above it.

Nothing else in the samples needed changing: fundWallet(), autofill(),
sign() and submitAndWait() all behave the same in 2.x.

Verification

All three samples were run against the Testnet with xrpl_php 2.3.0:

| Sample | Result |
| get-started/php/base.php | wallet created and funded |
| get-started/php/get-account-info.php | account data returned |
| send-xrp/php/send-xrp.php | tesSUCCESS |

The hardcoded example seed in send-xrp.php still has a funded Testnet account,
so that sample works as written.

Note

I maintain hardcastle/xrpl_php, so
happy to keep these samples current as the library moves. If a newer version
ever breaks them again, feel free to ping me.

The samples were written against v0.8.5, which used the namespace `XRPL_PHP\`.
The library moved to `Hardcastle\XRPL_PHP\`, so every sample fails with a
class-not-found error against any current version. The install instruction in
the tutorial is unpinned, so a reader following it gets 2.3.0 and none of the
code runs.

- Namespace corrected in the three code samples and in the inline blocks of
  both tutorials, 20 places in total
- The composer.json of both samples moves from ^0.8.5 to ^2.3
- get-started-php.md said PHP 8.1; the library requires 8.2 since 1.0.0 and
  declares it as a constraint since 2.0.0, so 8.1 cannot install it. ext-bcmath
  was missing from the requirements as well
- The comment naming the sample wallet's address did not match the seed above it

All three samples were run against the Testnet with 2.3.0; send-xrp.php reaches
tesSUCCESS.
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.

1 participant