Is pass by reference supported in php 7? - syntax-error

Recently we migrated PHP 5.6 to PHP 7
and now following code throws $this->a =& new test($this->f);
Parse error: syntax error, unexpected 'new' (T_NEW)
any ideas? what are the alternation that I could use for it?

As per the PHP7 incompatible changes: http://php.net/manual/en/migration70.incompatible.php
New objects cannot be assigned by reference
The result of the new statement can no longer be assigned to a
variable by reference: <?php class C {} $c =& new C; ?>
Output of the above example in PHP 5:
Deprecated: Assigning the return value of new by reference is
deprecated in /tmp/test.php on line 3
Output of the above example in PHP 7:
Parse error: syntax error, unexpected 'new' (T_NEW) in /tmp/test.php
on line 3
There is no alternative. You were using deprecated behavior, and now it's no longer valid PHP. Simply don't assign by reference.

To clarify Marc B's answer: just remove the ampersand like this
$this->a = new test($this->f);

You can do this as alternative:
$test = new test($this->f);
$this->a = $test;
now the $test is passed by reference and if you change attributes of $this->a, $test attributes will also change. and conversely.
PHP 7 is "pass by reference" by default. if you don't want to pass an object by it's reference, you should do this:
$a = clone $b;

Related

Type name 'serializeObject' does not exist in the type 'JsonConvert'

I am trying to convert some data to Json to send to the CloudFlare API. I am attempting to use Newtonsoft.Json.JsonConvert.SeriablizeObject() to accomplish this but I am getting the Intellisense error that the type name 'serializeObject' does not exist in the type 'JsonConvert'. I have the NuGet package Newtonsoft.Json installed but it does not recognize the SerializeObject() method. I am not sure what I am missing.
Its because you're calling the method wrong, remove the new operator from the line
var json = new JsonConvert.SerializeObject(updateDnsRecord);
to
var json = JsonConvert.SerializeObject(updateDnsRecord);

Problems regarding usage of Bodyguard library in Phoenix

We are trying to create a sample project using the Bodyguard library in Phoenix. We are just going to set some rules for users, as shown on the GitHub page, https://github.com/schrockwell/bodyguard. However, we are facing errors regarding the conn variable in lib\bg_web\controllers\post_controller.ex. We have uploaded our project in https://github.com/yashdani/bg. Please help us to identify the errors. Also, tell us what else we need to code in the project. We are really stuck, and we could not find any more information from the online documentation.
This is one of the errors:-
C:\Users\yashd\bg>mix phx.server
Compiling 18 files (.ex)
warning: variable "conn" does not exist and is being expanded to "conn()", please use parentheses to remove the ambiguity or change the variable name
lib/bg_web/controllers/post_controller.ex:6
== Compilation error in file lib/bg_web/controllers/post_controller.ex ==
** (CompileError) lib/bg_web/controllers/post_controller.ex:6: undefined function conn/0
(stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
(elixir) lib/kernel/parallel_compiler.ex:198: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6
You're missing the keyword do, instead of:
def update(conn, %{"id" => id, "post" => post_params})
should be:
def update(conn, %{"id" => id, "post" => post_params}) do

Is it possible to retrieve the namespace of a raised error?

When I raise an error from within an XQuery query, for instance with:
error( fn:QName( 'http://example.com', 'XMPL0001' ), 'Conflict' )
... the following is returned by BaseX (be it when communicating with the server, or from within the GUI)
Stopped at ., 1/7:
[XMPL0001] Conflict
Is it somehow possible to retrieve the namespace of the error (in this case http://example.com) as well?
I'm using a customized PHP client and I would like to use this information to prevent possible (future) conflicts with my custom error codes and parse the errors to throw either a standard BaseX\Exception or a custom SomeNamespace\Exception, depending on the namespace of the error.
I could, of course, simply use another error code pattern than the typical ABCD1234 XQuery pattern, to prevent possible (future) error code conflicts, but the possible use of a namespace appeals to me more, because I can then define an uniform Exception interface, such as:
interface ExceptionInterface
{
public function getCategory(); // the 4 alpha character part
public function getCode(); // the 4 digit part
}
I'm currently using BaseX 7.7.2, by the way.
Yes, you can retrieve information about the error using a few variables in the error namespace, which are in scope of the try-catch statement, like so:
declare namespace err = "http://www.w3.org/2005/xqt-errors";
try {
error( fn:QName( 'http://example.com', 'XMPL0001' ), 'Conflict' )
}
catch * {
namespace-uri-from-QName($err:code)
}
This assumes that you are using XQuery 3.0.

Groovy Sql Execute Statement won't accept closures

I have a statement:
sqlInstance.execute(executeString){
dummy, realList->
debug("Real LIst: "+realList)
}
which fails with 'Invalid column type'
But:
def bool = sqlInstance.execute(executeString)
works. If I print bool, it prints as 'true'.
For reference:
executeString = "select distinct channel_id from guide_sched"
For some reason, the closure isn't working for the execute method in groovy's Sql, although I've checked the documentation and it's supposed to.
It looks like the first environment I was testing on ran Groovy 2.4 and the second runs Groovy 2.1. The execute statement I was using didn't exist until after 2.1
Instead, I used the .rows() function to return a GroovyRowResult which I parsed for the information I needed, instead of accessing it directly in the .execute() closure.

Trying to use MAX(): "Fatal error: Undefined class constant"

$c = new Criteria();
$c->addSelectColumn('MAX('.Moto::matricula.')');
But i get this error:
Fatal error: Undefined class constant
'matricula' in /opt/lampp/htdocs/
prueba/lib/model/MotoPeer.php on line
25.
Any idea?
I'm using symfony 1.4 and propel 1.4.
Regards
Javi
It means that the class "Moto" doesn't have a variable "matricula" in it. This does not seem to have anything to do with (my)sql, but more with the (php?) class you are using.
Check out the source of that Moto class, and look if you have made a typo in the constant name?