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

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC] ## 概述 ByVal ``` // 第二參數為 Type 類型 ByVal(const char *name, Type type = Type::Null, bool required = true) // 第二參數輸入字符串 為類名 ByVal(const char *name, const char *classname, bool nullable = false, bool required = true) ByVal(const ByVal &argument) ``` Php::Type ``` Php::Type::Null Php::Type::Numeric Php::Type::Float Php::Type::Bool Php::Type::Array Php::Type::Object Php::Type::String Php::Type::Resource Php::Type::Constant Php::Type::ConstantArray Php::Type::Callable ``` ### 接收動態參數 - Php :: Parameters類不過是一個用Php :: Value對象填充的std :: vector,因此您可以對其進行迭代。 - 我們使用新的C ++ 11方法,并且使用new-for-C ++ 11“ auto”關鍵字要求編譯器找出參數向量中存儲了哪種類型的變量 ``` #include <phpcpp.h> Php::Value sum_everything(Php::Parameters &parameters) { int result = 0; for (auto &param : parameters) result += param; return result; } extern "C" { PHPCPP_EXPORT void *get_module() { static Php::Extension extension("my_extension", "1.0"); extension.add<sum_everything>("sum_everything"); return extension; } } ``` ``` <?php echo(myFunction(10,"100",20)."\n"); //130 ``` ### 接收指定參數 main.cpp ``` ... void example(Php::Parameters &params) { } extern "C" { PHPCPP_EXPORT void *get_module() { static Php::Extension myExtension("my_extension", "1.0"); myExtension.add<example>("example", { Php::ByVal("a", Php::Type::Numeric), Php::ByVal("b", "ExampleClass"), // 必須是 ExampleClass 類 Php::ByVal("c", "OtherClass") // 必須是 OtherClass 類 }); return myExtension; } } ``` main.php ``` class ExampleClass{ } class OtherClass{} // 第一參數 必須為整數,不然就報錯 // 第二參數 必須是ExampleClass 類 // 第三參數 必須是 OtherClass 類 example(1,new ExampleClass(),new OtherClass()); ``` ### 參數允許為空 ``` #include <phpcpp.h>; void example1(Php::Parameters &params) { Php::Value time = params[0]; ... } void example2(Php::Parameters &params) { Php::Value time = params[0]; ... } extern "C" { PHPCPP_EXPORT void *get_module() { static Php::Extension myExtension("my_extension", "1.0"); myExtension.add<example1>("example1", { Php::ByVal("time", "DateTime", false); }); myExtension.add<example2>("example2", { Php::ByVal("time", "DateTime", true); }); return myExtension; } } ``` main.php ``` // 不允許為空 function example1(DateTime $time) { ... } // 允許為空 function example1(DateTime $time = null) { Php::Value time = params[0]; ... } ``` ### 引用參數 ``` #include <phpcpp.h> #include <iostream> void example(Php::Parameters &params) { Php::Value temp=params[0]; params[0]=params[1]; params[1]=temp; } extern "C" { PHPCPP_EXPORT void *get_module() { static Php::Extension myExtension("my_extension", "1.0"); myExtension.add<example>("example", { Php::ByRef("a", Php::Type::Numeric), Php::ByRef("b", Php::Type::Numeric), }); return myExtension; } } ``` main.php ``` $a = 1; $b = 2; example($a, $b); print_r($a);//2 print_r($b);//1 ```
                  <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>

                              哎呀哎呀视频在线观看