# Adding custom code

> Learn how to add custom logic, methods, and dependencies to your PHP SDK. Step-by-step guide to extending Fern-generated PHP clients.

This page covers how to add custom logic, methods, and dependencies to your PHP SDK.

<Info>
  Before getting started, 

  [read about how Fern SDKs use custom code and learn about the `.fernignore` file](/sdks/overview/custom-code)

  .
</Info>

## Adding custom logic

To get started adding custom code:

<Steps>
  <Step title="Create a new file and add your custom logic">
    ```php title="src/Helper.php"
    <?php

    namespace YourNamespace;

    class Helper
    {
        public static function myHelper(): void
        {
            echo "Hello World!";
        }
    }
    ```
  </Step>

  <Step title="Add your file to `.fernignore`">
    ```yaml {3} title=".fernignore"
    # Specify files that shouldn't be modified by Fern

    src/Helper.php
    ```
  </Step>

  <Step title="Consume the helper">
    Now your users can consume the helper function by importing it from the SDK.

    ```php
    <?php

    use YourNamespace\Helper;

    Helper::myHelper();
    ```
  </Step>
</Steps>

## Adding custom SDK methods

Fern also allows you to add custom methods to the SDK itself (e.g.
`client.my_method()` ) by inheriting the Fern generated client and then
extending it.

<Steps>
  <Step title="Update `generators.yml` configuration">
    Name your Fern-generated client something like `BaseClient` to reflect that this client will be extended.

    ```yaml {4} title="generators.yml"
    - name: fernapi/fern-php-sdk
      version: 1.25.3
      config:
        clientName: BaseClient
    ```
  </Step>

  <Step title="Import and extend the generated client">
    First, import the Fern generated base client and extend it. Then, add whatever methods you want.

    ```php title="src/MyClient.php"
    <?php

    namespace YourNamespace;

    class MyClient extends BaseClient
    {
        public function myHelper(): void
        {
            echo "Hello World!";
        }
    }
    ```
  </Step>

  <Step title="Update `.fernignore`">
    Add the `MyClient.php` to `.fernignore`.

    ```diff title=".fernignore"
    + src/MyClient.php
    ```
  </Step>

  <Step title="Consume the method">
    Instead of constructing the generated client, your users will want to construct the extended client.

    ```php
    <?php

    use YourNamespace\MyClient;

    $client = new MyClient();
    ```

    Now your users can consume the helper function by importing it from the SDK.

    ```php
    $client->myHelper();
    ```
  </Step>
</Steps>

## Adding custom dependencies

To add packages that your custom code requires, update your `generators.yml` using the `composerJson` configuration option.

```yaml {4-8} title="generators.yml"
- name: fernapi/fern-php-sdk
  version: 1.25.3
  config:
    composerJson:
      require:
        guzzlehttp/guzzle: "^7.0"
      require-dev:
        phpunit/phpunit: "^10.0"
```