PHPackages                             alexeyyashin/ducktyping - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. alexeyyashin/ducktyping

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

alexeyyashin/ducktyping
=======================

Simple duck-typing implementation for PHP

v1.0.1(5y ago)040MITPHPPHP &gt;=7.0

Since Oct 12Pushed 5y ago1 watchersCompare

[ Source](https://github.com/alexeyyashin/ducktyping)[ Packagist](https://packagist.org/packages/alexeyyashin/ducktyping)[ RSS](/packages/alexeyyashin-ducktyping/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

ducktyping
==========

[](#ducktyping)

ducktyping is a simple **reflection-based** duck typing implementation for PHP

> If it walks like a duck and it quacks like a duck, then it must be a duck

- [Installation](#installation)
- [Basic usage](#basic-usage)
- [Explanation](#explanation)
- [Further](#further)

Installation
============

[](#installation)

With Composer:

```
composer require alexeyyashin/ducktyping
```

Without Composer:

- Copy repository files whereever you need
- Include autoload.php

```
include_once 'ducktyping-master/autoload.php';
```

Basic usage
===========

[](#basic-usage)

Check methods implementation

```
duck_check(Duck::class)->implementing(Bird::class);
```

Will return `true` if class `Duck` implements all that exist in class `Bird`(considering "static" modifier)

Note that you can use either class name (as `string`) or `object` both in `duck_check` function and `implementing`method

```
$duck = new Duck;
$bird = new Bird;

duck_check($duck)->implementing($bird);
```

---

Check single method existence

```
duck_check(Duck::class)->hasMethod('fly', $check_static)
```

Explanation
===========

[](#explanation)

Let's start with some basic independent classes

```
class Animal
{
    public function run() {}
}

class Plant
{
    public function growLeaves() {}
}
```

---

Then add some child class

```
class Bird extends Animal
{
    public function fly() {}
}
```

---

It's obvious that

```
var_dump(new Bird instanceof Animal); // bool(true)
```

---

But if we add some independent class

```
class Duck
{
    public function run() {}

    public function fly() {}

    public function quackle() {}
}
```

we will get

```
var_dump(new Duck instanceof Bird); // bool(false)
```

despite the fact it can both "run" and "fly" just because class `Duck` doesn't extend class `Bird` .

To check this by [duck typing (Wiki)](https://en.wikipedia.org/wiki/Duck_typing) we can see if class `Duck` has all the methods from class `Bird` using ducktyping

```
var_dump(duck_check(Duck::class)->implementing(Bird::class)); // bool(true)

// BUT, Duck does not have "growLeaves" method, so

var_dump(duck_check(Duck::class)->implementing(Plant::class)) // bool(false)
```

---

Multiple class implementation bonus

```
class Bulbasaur extends Pokemon
{
    public static $link = "https://en.wikipedia.org/wiki/Bulbasaur";

    public function run() {}

    public function growLeaves() {}

    public function fight() {}
}

$check = duck_check(new Bulbasaur);

$check->implementing(Pokemon::class) // true - because of inheritance
$check->implementing(Animal::class) // true - because of "run" method
$check->implementing(Plant::class) // true - because of "growLeaves" method
$check->implementing(Bird::class) // false - because of "fly" method absence
```

Further
=======

[](#further)

I wonder wheter we should check also public properties of testing classes/objects or not. So I need to uncomment that moment or remove it.

May be method signatures check will be added.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~51 days

Total

2

Last Release

1990d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/10206f77ccff237e4f6173d09004c86e5c8276845c023dde6b5c34797f79d203?d=identicon)[alexeyyashin](/maintainers/alexeyyashin)

---

Top Contributors

[![alexeyyashin](https://avatars.githubusercontent.com/u/47781271?v=4)](https://github.com/alexeyyashin "alexeyyashin (4 commits)")

### Embed Badge

![Health badge](/badges/alexeyyashin-ducktyping/health.svg)

```
[![Health](https://phpackages.com/badges/alexeyyashin-ducktyping/health.svg)](https://phpackages.com/packages/alexeyyashin-ducktyping)
```

###  Alternatives

[kartik-v/bootstrap-star-rating

A simple yet powerful JQuery star rating plugin for Bootstrap.

1.1k4.5M5](/packages/kartik-v-bootstrap-star-rating)[elegantly/laravel-seo

An Elegant &amp; flexible SEO tag builder for Laravel

122.9k](/packages/elegantly-laravel-seo)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
