AdobeDocs / AdobeDocs/commerce-php

Error while using code from docs

Open
#389 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
11
Forks
177
PR merge metrics
No merged PRs in 30d

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Expected behavior

I have tried code from https://developer.adobe.com/commerce/php/tutorials/frontend/custom-checkout/add-shipping-carrier/#step-3-create-the-carrier-model

While testing with PHP 8.3.4 (cli) (built: Mar 16 2024 08:39:49) (NTS) it is throwing an error

"Fatal Error: 'Type of ---\\Model\\Carrier\\Express::$_code must not be defined (as in class Magento\\Shipping\\Model\\Carrier\\AbstractCarrier)' in '.../Model\/Carrier\/Express.php' on line 18"

"Fatal Error: 'Type of ...\\Model\\Carrier\\Express::$_isFixed must not be defined (as in class Magento\\Shipping\\Model\\Carrier\\AbstractCarrier)' in '.../Model\/Carrier\/Express.php' on line 18"

Should be fixed in docs.

### Actual behavior

It should be corrected

protected string $_code = 'expressdelivery';

protected bool $_isFixed = true;

>>>

protected $_code = 'expressdelivery';

protected $_isFixed = true;

### Steps to reproduce

Create custom module from https://developer.adobe.com/commerce/php/tutorials/frontend/custom-checkout/add-shipping-carrier/#step-3-create-the-carrier-model

Run coomands
Go to cart or checkout

### Environment

- Browser:Chrome
- OS:Linux

### Sample code

protected string $_code = 'expressdelivery';

protected bool $_isFixed = true;

>>>

protected $_code = 'expressdelivery';

protected $_isFixed = true;

### Logs

"Fatal Error: 'Type of ---\\Model\\Carrier\\Express::$_code must not be defined (as in class Magento\\Shipping\\Model\\Carrier\\AbstractCarrier)' in '.../Model\/Carrier\/Express.php' on line 18"

"Fatal Error: 'Type of ...\\Model\\Carrier\\Express::$_isFixed must not be defined (as in class Magento\\Shipping\\Model\\Carrier\\AbstractCarrier)' in '.../Model\/Carrier\/Express.php' on line 18"

Contributor guide

Open the contributing guide

Research direction

Start with the Step 3 “Create the carrier model” section in the linked Adobe Commerce tutorial and compare its sample properties with Magento\Shipping\Model\Carrier\AbstractCarrier. Confirm the PHP 8.3 error and update the documented declarations so the example matches the parent class. Done means the tutorial no longer produces the reported typed-property errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.