syntax error, unexpected T_DOUBLE_ARROW inside class method [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Have been stuck with this little issue, when using key value arrays inside a class |I will get an error syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ']'
class hello{
public function name(){
$allnames = array("name"=>"mark" , "role" => "admin");
}
}

I have checked your code in my system there is no any error in your code
<?php
class hello{
public function name(){
$allnames = array("name"=>"mark" , "role" => "admin");
return $allnames;
}
}
$obj = new hello;
print_r($obj->name())
?>
Please check
You may try assign array as
$allnames = ["name"=>"mark" , "role" => "admin"];

Related

Libsodium "Call to undefined function sodium_randombytes_buf" [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Trying to follow the examples here, but it gives me
Fatal error: Uncaught Error: Call to undefined function sodium_randombytes_buf()
On top of that, the key pairs seems to be generating weird strings like:
kÿòjƒFDú{î—4]F◊î¸˜ßˆu…®_•A∞+.
Is that normal?
Here's my code
<?php
// send
$message = 'Hi, this is Alice';
$alice_to_bob_kp = sodium_crypto_box_keypair_from_secretkey_and_publickey(
file_get_contents('./keys/sec-user-1_box_key.txt'),
file_get_contents('./keys/pub-user-2_box_key.txt')
);
$nonce = sodium_randombytes_buf(SODIUM_CRYPTO_BOX_NONCEBYTES);
$ciphertext = sodium_crypto_box(
$message,
$nonce,
$alice_to_bob_kp
);
// receive
$bob_to_alice_kp = sodium_crypto_box_keypair_from_secretkey_and_publickey(
// $bob_box_secretkey,
// $alice_box_publickey
file_get_contents('./keys/sec-user-2_box_key.txt'),
file_get_contents('./keys/pub-user-1_box_key.txt')
);
$nonce = sodium_randombytes_buf(SODIUM_CRYPTO_BOX_NONCEBYTES);
$plaintext = sodium_crypto_box_open(
$ciphertext,
$nonce,
$bob_to_alice_kp
);
if ($plaintext === false) {
die("Malformed message or invalid MAC");
}
die($plaintext);
There is no such function as sodium_randombytes_buf() the code in the example uses \Sodium\randombytes_buf().
Edit:
From the bug history:
"The sodium_randombytes_* symbols have been removed a while back, as PHP now provide similar functions without this extension"
Bug #74896 sodium's .h defines some functions without .c implementation

Syntax error when accessing an array [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have a problem. I've created a class 'Game', and in this class I have an array named 'ShadowField'. This Field contains objects ('Fields'):
class Game extends Gameboard
{
public $ShadowField = array();
public $GameField = array();
public $Home = array();
function __construct($c,$h,$w,$m,$fc){
parent::__construct($c,$h,$w);
$counter = 1;
for($index_h=0; $index_h<11; $index_h++){
for($index_w=0; $index_w<11; $index_w++){
array_push($this->ShadowField, new Field(parent::$this, $m, "FF8000", ($h/11.1)*$index_h, ($w/11.15)*$index_w, true, $counter, $index_h, $index_w));
$counter++;
}
}
$PlayerRed = new PlayerHome($this, $m, "FF0000", 0);
}
}
Then, in my next class, I tried to use this array, but then I got an error:
for($i=0;$i<4;$i++){
parent::__construct($game,$m,$c,$game->ShadowField[$FieldID[$i]]->Top,ShadowField[$FieldID[$i]]->Left);
}
Error:
Parse error: syntax error, unexpected '[' in C:\XAMPP\xampp\htdocs\ot\madn\Game.class.php on line 63
I don't understand it because it's an array, and I am calling it like an array, so what is the problem?
The "FieldID" is an array, too:
class PlayerHome extends Field
{
public $Color;
public $Player;
public $FieldID = array();
function __construct(Game $game, $m, $c, $p){
switch($p){
case 0: array_push($FieldID,1,2,12,13);
case 1: array_push($FieldID,10,11,21,22);
case 2: array_push($FieldID,100,101,111,112);
case 3: array_push($FieldID,109,110,120,121);
default:echo "Player_$p existiert nicht, bitte eine SpielerID zwischen 0-3 wählen.";
}
for($i=0;$i<4;$i++){
parent::__construct($game,$m,$c,$game->ShadowField[$FieldID[$i]]->Top,ShadowField[$FieldID[$i]]->Left);
}
}
}
(p.s.: Sorry for bad english)
You use it correctly the first time:
$game->ShadowField[$FieldID[$i]]->Top
However the second time you call ShadowField by itself without referencing the object:
ShadowField[$FieldID[$i]]->Left
Replace the line in the loop with this (formatted for visibility):
parent::__construct($game,
$m,
$c,
$game->ShadowField[$FieldID[$i]]->Top,
$game->ShadowField[$FieldID[$i]]->Left);

I get this error Parse error: syntax error, unexpected '[' [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
<?php
// configuration
require("../includes/config.php");
render("home_form.php", ["title" => "Log In"]);
?>
/**
* Renders template, passing in values.
*/
function render($template, $values = [])
{
// if template exists, render it
if (file_exists("../templates/$template"))
{
// extract variables into local scope
extract($values);
// render header
require("../templates/header.php");
// render template
require("../templates/$template");
// render footer
require("../templates/footer.php");
}
// else err
else
{
trigger_error("Invalid template: $template", E_USER_ERROR);
}
}
replace render("home_form.php", ["title" => "Log In"]);
with
render("home_form.php", array("title" => "Log In"));
and
$values = []
with
$values = array()
Which PHP version do you use?
Short array syntax is available since PHP 5.4.0: http://php.net/manual/en/migration54.new-features.php

unexpected T_IF, expecting ')' [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
Parse error: syntax error, unexpected T_IF, expecting ')'
What should I do?
$show_smileys = true;
$find = array(
'!\[h1\](.+)\[/h1\]!isU',
'!\[b\](.+)\[/b\]!isU',
'!\[i\](.+)\[/i\]!isU',
'!\[u\](.+)\[/u\]!isU',
'!\[strike\](.+)\[/strike\]!isU',
'!\[spoiler\](.+)\[/spoiler\]!isU',
'!\[url=(.*?)\](.*?)\[/url\]!is',
'!\[player\](.+)\[/player\]!isU',
'!\[quote=(.*)\]!siU',
'!\[/quote\]!si'
if ($show_smileys == true) {
,'#:p#is',
'#:eek:#is',
'#:rolleyes:#is',
'#;\)#is',
'#:o#is',
'#:D#is',
'#:\(#is',
'#:mad:#is',
'#:\)#is',
'#:cool:#is'
}
);
You can't include an if condition inside an array. Define the primary portion of your array like this:
$find = array(
'!\[h1\](.+)\[/h1\]!isU',
'!\[b\](.+)\[/b\]!isU',
'!\[i\](.+)\[/i\]!isU',
'!\[u\](.+)\[/u\]!isU',
'!\[strike\](.+)\[/strike\]!isU',
'!\[spoiler\](.+)\[/spoiler\]!isU',
'!\[url=(.*?)\](.*?)\[/url\]!is',
'!\[player\](.+)\[/player\]!isU',
'!\[quote=(.*)\]!siU',
'!\[/quote\]!si'
);
And then use a condition to merge the rest:
if ($show_smileys == true) {
$smiles = array(
'#:p#is',
'#:eek:#is',
'#:rolleyes:#is',
'#;\)#is',
'#:o#is',
'#:D#is',
'#:\(#is',
'#:mad:#is',
'#:\)#is',
'#:cool:#is'
);
$final = array_merge($find, $smiles);
}
You can't put if in the middle of an array, it can only be used where statements are allowed. Do it this way:
$find = array(
'!\[h1\](.+)\[/h1\]!isU',
'!\[b\](.+)\[/b\]!isU',
'!\[i\](.+)\[/i\]!isU',
'!\[u\](.+)\[/u\]!isU',
'!\[strike\](.+)\[/strike\]!isU',
'!\[spoiler\](.+)\[/spoiler\]!isU',
'!\[url=(.*?)\](.*?)\[/url\]!is',
'!\[player\](.+)\[/player\]!isU',
'!\[quote=(.*)\]!siU',
'!\[/quote\]!si'
);
$smileys = array(
'#:p#is',
'#:eek:#is',
'#:rolleyes:#is',
'#;\)#is',
'#:o#is',
'#:D#is',
'#:\(#is',
'#:mad:#is',
'#:\)#is',
'#:cool:#is'
);
if ($show_smileys) {
$find = array_merge($find, $smileys);
}

PHP: Catchable fatal error: Object of class stdClass could not be converted to string [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I get the following dump & error when running the attached code. What I'm confused by is that $procID appears to be returned as a string, but as soon as I attempt to pass it again, its an object? How do I get it to be/stay a string? Thanks.
object(stdClass)#2 (1) {
["processId"]=> string(13)
"Genesis114001" } string(311)
"Genesis114001" string(293) " Genesis
" Catchable fatal error: Object of
class stdClass could not be converted
to string in
C:\wamp\www\SugarCE\testSOAPShawn.php
on line 15
<?php
set_time_limit(0);
require_once('nusoap.php');
require_once('BenefitSOAP.php'); //WSDL to PHP Classes
$client = new SoapClient('C:\wsdl\BenefitDeterminationProcess_BenefitDialogueServiceSOAP.wsdl', array('trace' => 1));
$procID = $client->start(array("prefix"=>"Genesis"));
$respXML = $client->__getLastResponse();
$requXML = $client->__getLastRequest();
echo "<p/>";
var_dump($procID);
//echo "<p/>";
var_dump($respXML);
//echo "<p/>";
var_dump($requXML);
$exchange = $client->exchangeOptions(array("processId"=>$procID)); //LINE 15
$end = $client->stop(array("processId"=>$procID));
?>
Whatever the $client->start() method is returning, it is typed as an object. You can access the properties of the object using the -> operator:
$procID = $client->start(array("prefix"=>"Genesis"));
...
$exchange = $client->exchangeOptions(array("processId"=>$procID->processId));
This was probably an array, but is getting typed into an object. Thus, you end up with the stdClass.
Another (and possibly better) way to do this is to type the return. That way, you don't have to make a new array for later passing as argument:
$procID = (array) $client->start(array("prefix"=>"Genesis"));
...
$exchange = $client->exchangeOptions($procID);
$end = $client->stop($procID);

Categories