ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
[TOC] ## 概述 扩展了php 中没有的额外功能 ## 示例 ### 支持 __toInteger(),__toFloat()和__toBool() <details> <summary>main.cpp</summary> ``` #include <phpcpp.h> class MyClass : public Php::Base { public: MyClass() = default; virtual ~MyClass() = default; const char *__toString() { return "abcd"; } int __toInteger() { return 1234; } double __toFloat() { return 88.88; } bool __toBool() { return true; } }; extern "C" { PHPCPP_EXPORT void *get_module() { static Php::Extension myExtension("my_extension", "1.0"); Php::Class<MyClass> myClass("MyClass"); myExtension.add(std::move(myClass)); return myExtension; } } ``` </details> <br /> <details> <summary>main.php</summary> ``` <?php // initialize an object $object = new MyClass(); // cast it echo((string)$object."\n"); // abcd echo((int)$object."\n"); // 1234 echo((bool)$object."\n"); // 1 echo((float)$object."\n"); // 88,88 ``` </details> <br />