I am trying to make simple php extension via zephir, but zephir does not want to work.
Here is my code:
namespace Const;
class Hello {
public static function world() {
echo "Hello World!";
}
}
And here is the error it produces on zephir build:
Zephir\ParseException: Syntax error in /root/compile/const/const/hello.zep on line 1
namespace Const;
---------------^
const is a reserved word in PHP: http://php.net/manual/fr/reserved.keywords.php. You should try another namespace.
Related
MyActor.h
UCLASS()
class FPS_API AMyActor: public AActor
{
GENERATED_BODY()
...
public:
UFUNCTION(NetMulticast, Reliable)
void MulticastRPCMyFunction();
...
}
MyActor.cpp
void AMyActor::MulticastRPCMyFunction()
{
UE_LOG(LogTemp, Log, TEXT("Message"));
}
When i compile my project, i can check the error message below.
Compile error
*.gen.cpp.obj : error LNK2005: "public: void __cdecl *::MulticastRPCMyFunction(void)" (?MulticastRPCMyFunction#*##QEAAXXZ) already defined in *.cpp.obj
With networked functions (in your case the NetMulticast metadata) you do not name the function the same thing in the Cpp file as the header file because it gets generated by UHT (hence the linker error about it already being defined).
In your case your Cpp file would need to look like this:
void AMyActor::MulticastRPCMyFunction_Implementation()
{
UE_LOG(LogTemp, Log, TEXT("Message"));
}
Notice the _Implementation addition to the function name.
If you ever add the WithValidation metadata, then you would need another function with _Validate added to the end of the function name.
I have created a library in C# to be used in Q# programs. The library has two scripts, a C# class library called "Class1.cs" and a matching Q# script called "Util.qs", I share the code snippet of each here:
Class1.cs:
using System;
using Microsoft.Quantum.Simulation.Common;
using Microsoft.Quantum.Simulation.Core;
using Microsoft.Quantum.Simulation.Simulators;
namespace MyLibrary {
class Class1 : QuantumSimulator {
static void Method_1 (string str) { ... }
.
.
.
}
}
Util.qs:
namespace MyLibrary {
operation Op_1 (str : String) : Unit { body intrinsic; }
}
There is another Q# program in a different namespace that uses the namespace "MyLibrary" so after adding reference, in this Q# program I have:
namespace QSharp
{
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Intrinsic;
open MyLibrary;
operation TestMyLibrary() : Unit {
Op_1("some string");
}
}
When I execute "dotnet run" in the terminal I receive this message:
Unhandled Exception: System.AggregateException: One or more errors
occurred. (Cannot create an instance of MyLibrary.Op_1 because it is
an abstract class.) ---> System.MemberAccessException: Cannot create
an instance of MyLibrary.Op_1 because it is an abstract class.
How can I fix it?
Thanks.
UPDATE:
Following Mariia' answer and also checking Quantum.Kata.Utils, I changed my code as following:
So, I changed Class1 script to:
using System;
using Microsoft.Quantum.Simulation.Common;
using Microsoft.Quantum.Simulation.Core;
using Microsoft.Quantum.Simulation.Simulators;
namespace MyLibrary {
class Class1 : QuantumSimulator {
private string classString = "";
public Class1() { }
public class Op_1_Impl : Op_1{
string cl_1;
public Op_1_Impl (Class1 c) : base (c) {
cl_1 = c.classString;
}
public override Func<string, QVoid> Body => (__in) => {
return cl1;
};
}
}
Now the error messages are:
error CS0029: Cannot implicitly convert type 'string' to 'Microsoft.Quantum.Simulation.Core.QVoid'
error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types
in the block are not implicitly convertible to the delegate return type
Having checked Quantum.Kata.Utils, I realised I need to create a field and a constructor for Class1 which is a base class and also I should override Func<string, QVoid> as the Op_1 parameter is string type. But I am not sure if each of these steps individually is done properly?
Second Update:
I have changed the previous c# code in first update to the following one:
using System;
using Microsoft.Quantum.Simulation.Common;
using Microsoft.Quantum.Simulation.Core;
using Microsoft.Quantum.Simulation.Simulators;
namespace MyLibrary {
class Class1 : QuantumSimulator {
public Class1() { }
public class Op_1_Impl : Op_1{
Class1 cl_1;
public Op_1_Impl (Class1 c) : base (c) {
cl_1 = c;
}
public override Func<string, QVoid> Body => (__in) => {
return QVoid.Instance;
};
}
}
Now the error message is the same as the very first one:
Unhandled Exception: System.AggregateException: One or more errors
occurred. (Cannot create an instance of MyLibrary.Op_1 because it is
an abstract class.) ---> System.MemberAccessException: Cannot create
an instance of MyLibrary.Op_1 because it is an abstract class.
And also in this new code shouldn't the constructor public Class1() { } have a parameter? if so what datatype?
In your code, there is nothing connecting the Q# operation Op_1 and the C# code that you intend to implement it in Method_1.
Q# operations are compiled into classes. To define a C# implementation for a Q# operation with the intrinsic body, you have to define a class that implements the abstract class into which your Q# operation gets compiled; so you would have something like public class Op_1_Impl : Op_1.
Getting all the piping right can be a bit tricky (it's a hack, after all!) I would recommend looking at the operation GetOracleCallsCount and its C# implementation to see the exact pieces that have to be in place for it to work.
For the updated question, the signature of your method says that it takes string as an input and returns nothing (QVoid), but the implementation tries to return a string cl_1, so you get a Cannot implicitly convert type 'string' to 'Microsoft.Quantum.Simulation.Core.QVoid'.
To provide a custom C# emulation for your Op_1 Q# operation, you'll need to replace your Class1.cs with something like this:
using System;
using Microsoft.Quantum.Simulation.Core;
namespace MyLibrary
{
public partial class Op_1
{
public class Native : Op_1
{
public Native(IOperationFactory m) : base(m) { }
public override Func<String, QVoid> Body => (str) =>
{
// put your implementation here.
Console.WriteLine(str);
return QVoid.Instance;
};
}
}
}
You can then run the Test1Library using the QuantumSimulator.
That being said, as Mariia said, this is kind of hacky, undocumented functionality that might change in the future, may I ask why you need this?
I am setting the VM arguments in eclipse as -DFilePath="C:\file\txt"
But while calling this #FilePath# in java it is giving output as C:filetxt instead of C:\file\txt. This is resulting in file not found exception. Can anyone please help me on this..
The problem must be in how you are "calling this #FilePath#".
I tested with following code:
package test;
import java.io.File;
public class EnvPath {
public static void main(String[] args) {
String path = System.getProperty("FilePath");
System.out.println("Prop: " + path);
File file = new File(path);
System.out.println("File: " + file);
}
}
Started from Eclipse, as you described, or with java -DFilePath="C:\file\txt" test.EnvPath using Windows Command Prompt and using GNU bash - it always produces:
Prop: C:\file\txt
File: C:\file\txt
How can I implement mysqli in an extended class?
I am uploading an image and storing it in a MySQL database, but I get this error:
Notice: Undefined variable: mysqli in ...ecc/ecc/ on line 33
Fatal error: Call to a member function query() on a non-object in ...ecc/ecc/ on line 33
Here is my test code:
<?php
interface ICheckImage {
public function checkImage();
public function sendImage();
}
abstract class ACheckImage implements ICheckImage {
public $image;
private $mysqli;
public function _construct(){
$this->image = $_POST['image'];
$this->mysqli = new mysqli('localhost','test','test','test');
}
}
class Check extends ACheckImage {
public function checkImage() {
if($this->image > 102400) {
echo "File troppo grande";
}
}
public function sendImage() {
//This is the line 33 give me the error
if ($mysqli->query("INSERT INTO images (image) VALUES ('$this->image')")) {
echo "Upload avvenuto  ";
} else {
echo "Errore  " . $mysqli->error;
}
}
}
$form = new Check();
$form->checkImage();
$form->sendImage();
?>
There are some errors in your code.
The $mysqli member is private inside the abstract class. It will not be inherited by the Check class, so it does not exist there. Make it protected.
Access to the members of a class always needs $this-> in front, specifically $this->mysqli in this instance.
The constructor function must be named __construct with two underscores in front.
The image check looks wrong. $_POST['image'] does contain something that you expect to store in the database, but you also compare it with an integer value and seem to echo an error message if it is bigger. While the data handling will work, e.g. you can compare a string from POST data with an integer, it looks like you want something else.
I'm trying to load an external library into an ExpressionEngine plugin but am getting:
Message: Undefined property: Detector::$EE
In the plugin itself I've got:
public function __construct()
{
$this->EE->load->library('detector');
$this->EE =& get_instance();
}
and my folders are set up like:
detector
-libraries
--Detector.php
-pi.detector.php
What am I doing wrong?
Having moved past the loading library error, I'm now getting an 'undefined variable' error with the following code:
public function detector()
{
return $ua->ua;
}
public function user_agent()
{
return $ua->ua;
}
That's if I have {exp:detector:user_agent} in my template. If I {exp:detector} I get no output.
you should change your code like this:
$this->EE =& get_instance();
$this->EE->load->add_package_path(PATH_THIRD.'/detector');
$this->EE->load->library('detector');
First initialize the $this->EE variable, then you can load the library. So in this case it would be
$this->EE->detector->user_agent();