<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] ## 示例 ### 繼承可數 Countable 接口 Countable 接口 ``` Countable { /* 方法 */ abstract public count ( void ) : int } ``` <details> <summary>main.cpp</summary> ``` #include <phpcpp.h> class Counter : public Php::Base, public Php::Countable { private: int _value = 0; public: Counter() {} virtual ~Counter() {} Php::Value increment() { return ++_value; } Php::Value decrement() { return --_value; } virtual long count() override { return _value; } }; extern "C" { PHPCPP_EXPORT void *get_module() { static Php::Extension myExtension("my_extension", "1.0"); Php::Class<Counter> counter("Counter"); counter.method("increment", &Counter::increment); counter.method("decrement", &Counter::decrement); myExtension.add(std::move(counter)); // return the extension return myExtension; } } ``` </details> <br /> <details> <summary>main.php</summary> ``` <?php $counter = new Counter(); $counter->increment(); $counter->increment(); $counter->increment(); echo(count($counter)."\n"); // 3 ``` </details> <br /> ### ArrayAccess 接口 將對象行為轉為數組 格式: ``` ArrayAccess { /* 方法 */ abstract public offsetExists ( mixed $offset ) : boolean abstract public offsetGet ( mixed $offset ) : mixed abstract public offsetSet ( mixed $offset , mixed $value ) : void abstract public offsetUnset ( mixed $offset ) : void } ``` <details> <summary>main.cpp</summary> ``` #include <phpcpp.h> class Map : public Php::Base, public Php::Countable, public Php::ArrayAccess { private: std::map<std::string, std::string> _map; public: Map() {} virtual ~Map() {} virtual long count() override { return _map.size(); } virtual bool offsetExists(const Php::Value &key) override { return _map.find(key) != _map.end(); } virtual void offsetSet(const Php::Value &key, const Php::Value &value) override { _map[key] = value.stringValue(); } virtual Php::Value offsetGet(const Php::Value &key) override { return _map[key]; } virtual void offsetUnset(const Php::Value &key) override { _map.erase(key); } }; extern "C" { PHPCPP_EXPORT void *get_module() { static Php::Extension myExtension("my_extension", "1.0"); Php::Class<Map> map("Map"); myExtension.add(std::move(map)); return myExtension; } } ``` </details> <br /> <details> <summary>main.php</summary> ``` <?php <?php $map = new Map(); $map["a"] = 1234; $map["b"] = "xyz"; $map["c"] = 0; unset($map['a']); var_dump($map["a"]) . PHP_EOL; // string: "" var_dump($map["b"]) . PHP_EOL; // string: "xyz" var_dump($map["c"]) . PHP_EOL; // string: "0" var_dump($map["d"]) . PHP_EOL; // string:"" //這會導致一個致命錯誤, // ArrayAccess方法沒有導出到用戶空間 echo ($map->offsetGet("a") . "\n"); ``` </details> <br /> ### foreach 進行迭代(測試失敗) ### 可序列化的接口 <details> <summary>main.cpp</summary> ``` #include <phpcpp.h> class Counter : public Php::Base, public Php::Serializable { private: int _value = 0; public: Counter() = default; virtual ~Counter() = default; Php::Value increment() { return ++_value; } Php::Value decrement() { return --_value; } Php::Value value() const { return _value; } virtual std::string serialize() override { return std::to_string(_value); } virtual void unserialize(const char *buffer, size_t size) override { _value = std::atoi(buffer); } }; extern "C" { PHPCPP_EXPORT void *get_module() { static Php::Extension myExtension("my_extension", "1.0"); Php::Class<Counter> counter("Counter"); counter.method<&Counter::increment>("increment"); counter.method<&Counter::decrement>("decrement"); counter.method<&Counter::value>("value"); myExtension.add(std::move(counter)); return myExtension; } } ``` </details> <br /> <details> <summary>main.php</summary> ``` <?php // create an empty counter and increment it a few times $counter = new Counter(); $counter->increment(); $counter->increment(); // turn the counter into a storable string $serializedCounter = serialize($counter); // revive the counter back into an object $revivedCounter = unserialize($serializedCounter); // show the counter value echo($revivedCounter->value()."\n");//2 ?> ``` </details> <br />
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看