{"id":36331506,"url":"https://github.com/thoroughphp/typecasting","last_synced_at":"2026-01-11T12:00:42.580Z","repository":{"id":62542742,"uuid":"155769214","full_name":"ThoroughPHP/TypeCasting","owner":"ThoroughPHP","description":null,"archived":false,"fork":false,"pushed_at":"2018-11-03T11:45:26.000Z","size":437,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-14T14:45:05.493Z","etag":null,"topics":["downcast","php","typecast","types"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ThoroughPHP.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-01T20:03:25.000Z","updated_at":"2019-08-02T20:46:57.000Z","dependencies_parsed_at":"2022-11-02T16:16:22.846Z","dependency_job_id":null,"html_url":"https://github.com/ThoroughPHP/TypeCasting","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ThoroughPHP/TypeCasting","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThoroughPHP%2FTypeCasting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThoroughPHP%2FTypeCasting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThoroughPHP%2FTypeCasting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThoroughPHP%2FTypeCasting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ThoroughPHP","download_url":"https://codeload.github.com/ThoroughPHP/TypeCasting/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThoroughPHP%2FTypeCasting/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28301985,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T11:18:18.743Z","status":"ssl_error","status_checked_at":"2026-01-11T11:07:56.842Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["downcast","php","typecast","types"],"created_at":"2026-01-11T12:00:23.358Z","updated_at":"2026-01-11T12:00:42.568Z","avatar_url":"https://github.com/ThoroughPHP.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TypeCasting - kind of explicit type casting in PHP\n\n[![Build Status](https://travis-ci.com/Sevavietl/TypeCasting.svg?branch=master)](https://travis-ci.com/Sevavietl/TypeCasting)\n[![Coverage Status](https://coveralls.io/repos/github/Sevavietl/TypeCasting/badge.svg)](https://coveralls.io/github/Sevavietl/TypeCasting)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-brightgreen.svg?style=flat)](https://github.com/phpstan/phpstan)\n\nNeither real [covariance](https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)) in method return type hints, nor [explicit type casting](https://www.baeldung.com/java-type-casting) are supported in PHP.\n\nSometimes it is useful to downcast object, so PhpStorm or PHPStan stop complaining about absent methods or mismatched types.\n\nUsually [@var](http://docs.phpdoc.org/references/phpdoc/tags/var.html) tag used for this. But as with all phpdoc tags in regard of typing, this is simply telling your IDE or static analyzer tool to take your honest word that you know for sure the type of the stuff.\n\nWhereas with actual type casting (like say in java, C# or even in PHP, but only for primitives) you can be sure that object (or primitive) is \"castable\" into specified type, or end up with exception.\n\nSo you can plug `\\TypeCasting\\TypeCasting` trait into your class (but only one per inheritance chain) and then use `cast` method that is a bit like [`Java.lang.Class.cast`](https://www.tutorialspoint.com/java/lang/class_cast.htm) method (but of course this is oversimplified comparison).\n\n![downcasting](images/downcasting.gif)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoroughphp%2Ftypecasting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthoroughphp%2Ftypecasting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoroughphp%2Ftypecasting/lists"}