> This page is for SDKs, version Current (default).
> For other versions, use one of these documentation indexes:
> - Current (default): https://buildwithfern.com/learn/sdks/current/llms.txt
> - Legacy: https://buildwithfern.com/learn/sdks/legacy/llms.txt

> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt.

# 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.

> **Enterprise feature**
>
> This feature is available only for the [Enterprise plan](https://buildwithfern.com/pricing). To get started, reach out to [support@buildwithfern.com](mailto:support@buildwithfern.com).

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

## Adding custom logic

To get started adding custom code:

> **Note**
>
> These steps cover adding a new custom file to the SDK. To preserve line-level edits to a generated file, use [Replay](/learn/sdks/overview/custom-code#replay) instead.

#### Create a new file and add your custom logic

**`src/Helper.php`**

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

namespace YourNamespace;

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

#### Add your file to \`.fernignore\`

**`.fernignore`**

```yaml {3} title=".fernignore"
# Specify files that shouldn't be modified by Fern

src/Helper.php
```

#### Consume the helper

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

```php
<?php

use YourNamespace\Helper;

Helper::myHelper();
```

## 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.

#### Update \`sdk-config.yml\` configuration

Name your Fern-generated client something like `BaseClient` to reflect that this client will be extended.

**`sdk-config.yml`**

```yaml {5} title="sdk-config.yml"
targets:
  - language: php
    generation:
      naming:
        clientName: BaseClient
```

#### Import and extend the generated client

First, import the Fern generated base client and extend it. Then, add whatever methods you want.

**`src/MyClient.php`**

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

namespace YourNamespace;

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

#### Update \`.fernignore\`

Add the `MyClient.php` to `.fernignore`.

**`.fernignore`**

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

#### 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();
```

## Adding custom dependencies

To add packages that your custom code requires, list them in the target's `package.extraDependencies` and `package.extraDevDependencies` in `sdk-config.yml`.

**`sdk-config.yml`**

```yaml {4-10} title="sdk-config.yml"
targets:
  - language: php
    package:
      extraDependencies:
        - name: guzzlehttp/guzzle
          version: "^7.0"
      extraDevDependencies:
        - name: phpunit/phpunit
          version: "^10.0"
```