Parse error: syntax error, unexpected '[' - php

i am trying to install a sdk on a public cloud service.The code is shown as follow:
<?php
echo ( '<meta charset="utf-8">');
date_default_timezone_set('PRC');
require_once __DIR__ . '/lib/KdtApiClient.php';
$appId = 'xxx';
$appSecret = 'xxx';
$client = new KdtApiClient($appId, $appSecret);
$method = 'kdt.users.weixin.followers.get';
$params = [
// 'tid' => 'E20150126200526848473',
//'num_iid' => 1005950256201501260011172648,
//'title' => 'api 测试商品 编辑 __ 22',
//'desc' => 'description here',
//'post_fee' => 0.2,
'page_size'=>5000,
];
$files = [
[
'url' => __DIR__ . '/file1.png',
'field' => 'images[]',
],
[
'url' => __DIR__ . '/file2.jpg',
'field' => 'images[]',
],
];
echo '<pre>';
var_dump(
$client->post($method, $params, $files)
);
echo '</pre>';
?>
I got this error:
Parse error: syntax error, unexpected '[' in php-sdk/index.php on line 12
The code works well on local xampp.Is there anyone can tell me what's the problem?

The issue you are encountering is most likely due to different PHP versions.
On line 12 you are using the short array syntax to create an array on the files variable. $files = [...
This syntax was introduced in PHP 5.4 (See second point). However I think the cloud service is not using 5.4, which is why you don't have the short array syntax. The easy solution would be to use $files = array( instead.

Related

quickbooks php sdk class not found

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require "vendor/autoload.php";
use QuickBooksOnline\API\DataService\DataService;
use QuickBooksOnline\API\Facades\Invoice;
use QuickBooksOnline\API\Facades\PurchaseOrder;
$dataService = DataService::Configure(array(
'auth_mode' => 'oauth1',
'consumerKey' => " ",
'consumerSecret' => " ",
'accessTokenKey' => " ",
'accessTokenSecret' => " ",
'QBORealmID' => "",
'baseUrl' => "https://quickbooks.api.intuit.com/"
));
for($i = 1; $i<= 3; $i ++){
$LineObj = Line::create([
"Id" => $i,
"LineNum" => $i,
"Description" => "Pest Control Services",
"Amount" => 35.0,
"DetailType" => "SalesItemLineDetail",
"SalesItemLineDetail" => [
"ItemRef" => [
"value" => "1",
"name" => "Pest Control"
],
"UnitPrice" => 35,
"Qty" => 1,
"TaxCodeRef" => [
"value" => "NON"
]
]
]);
$lineArray[] = $LineObj;
}
//Add a new Invoice
$theResourceObj = PurchaseOrder::create([
"Line" => $lineArray,
"CustomerRef"=> [
"value"=> "1"
],
"BillEmail" => [
"Address" => "Familiystore#intuit.com"
],
"BillEmailCc" => [
"Address" => "a#intuit.com"
],
"BillEmailBcc" => [
"Address" => "v#intuit.com"
]
]);
?>
Fatal error: Uncaught Error: Class 'Line' not found in /var/www/html/QuickBooks-V3-PHP-SDK-master/Test2.php:24
purchaseOrder.php:
<?php
//require "vendor/autoload.php";
include('src/config.php');
use QuickBooksOnline\API\DataService\DataService;
use QuickBooksOnline\API\Facades\Invoice;
use QuickBooksOnline\API\Facades\PurchaseOrder;
// OBOT Data service
$dataService = DataService::Configure(array(
'auth_mode' => 'oauth1',
'consumerKey' => " ",
'consumerSecret' => " ",
'accessTokenKey' => " ",
'accessTokenSecret' => " ",
'QBORealmID' => " ",
'baseUrl' => "https://quickbooks.api.intuit.com/"
));
$linedet = new IPPPurchaseOrderItemLineDetail();
$linedet->CustomerRef = 86;
$line = new IPPLine();
$line->Id = 0;
$line->Description = 'test purchase order';
$line->Amount = 2.00;
$line->DetailType= 'ItemBasedExpenseLineDetail ';
$line->ItemBasedExpenseLineDetail = $linedet;
$line->BillableStatus = 'Notbillable';
$line->ItemRef = '19';
$line->UnitPrice = '25';
$line->Qty = '1';
$purchaseOrder = new IPPPurchaseOrder();
$purchaseOrder->Line = $line;
$purchaseOrder->VendorRef = 85;
$purchaseOrder->APAccountRef = 1;
$purchaseOrder->TotalAmt = 200.00;
$result = $dataService->Add($purchaseOrder); //add purchase order
?>
PHP Fatal error: Uncaught Error: Class 'IPPPurchaseOrderItemLineDetail' not found in /var/www/html/QuickBooks-V3-PHP-SDK-master/purchaseOrder.php:20
Why am I getting these errors? is the autoload not working? should I just directly include the class files that I need?
In regards your first error below:
Fatal error: Uncaught Error: Class 'Line' not found in /var/www/html/QuickBooks-V3-PHP-SDK-master/Test2.php:24
I don't see you including the Line class anywhere, from the GitHub page here I have truncated their advice:
Connecting to the QuickBooks Online API
Currently the below API entity Endpoints support creating Objects from Array:
Estimate
Line
Invoice
Item
For create/update above entity endpoints, you are going to import corresponding facade class:
use QuickBooksOnline\API\Facades\{Facade_Class_Name};
As such you need to update your first script to include this Facade, which should be as simple as:
<?php
require "vendor/autoload.php";
use QuickBooksOnline\API\DataService\DataService;
use QuickBooksOnline\API\Facades\Invoice;
use QuickBooksOnline\API\Facades\PurchaseOrder;
use QuickBooksOnline\API\Facades\Line; // <-- You are missing this line
In regards the second error below:
PHP Fatal error: Uncaught Error: Class 'IPPPurchaseOrderItemLineDetail' not found in /var/www/html/QuickBooks-V3-PHP-SDK-master/purchaseOrder.php:20
From searching the GitHub codebase again I can see this class is declared here. Therefore it should be as simple as declaring this again in your use statements at the top of the file that is using this, such as below:
<?php
//require "vendor/autoload.php";
include('src/config.php');
use QuickBooksOnline\API\DataService\DataService;
use QuickBooksOnline\API\Facades\Invoice;
use QuickBooksOnline\API\Facades\PurchaseOrder;
use QuickBooksOnline\API\Data\IPPPurchaseOrderItemLineDetail; // <-- You are missing this line
Looking at the rest of your code there seems to be a lot of classes that you are not declaring through use statements such as PurchaseOrder, IPPLine and IPPPurchaseOrder which you will also need to include.

S3Client PHP SDK: Object of class <class> could not be converted to string

I get the following errors when I try to use the AWS PHP SDK:
PHP Warning: Illegal string offset 'client.backoff' in C:\xampp\htdocs\aws_test_local\vendor\aws\aws-sdk-php\src\Aws\S3\S3Client.php on line 172
PHP Catchable fatal error: Object of class Guzzle\Plugin\Backoff\BackoffPlugin could not be converted to string in C:\xampp\htdocs\aws_test_local\vendor\aws\aws-sdk-php\src\Aws\S3\S3Client.php on line 172
PHP Warning: Illegal string offset 'signature' in C:\xampp\htdocs\aws_test_local\vendor\aws\aws-sdk-php\src\Aws\S3\S3Client.php on line 175
PHP Catchable fatal error: Object of class Aws\S3\S3Signature could not be converted to string in C:\xampp\htdocs\aws_test_local\vendor\aws\aws-sdk-php\src\Aws\S3\S3Client.php on line 175
They originate from the following code inside the S3Client.php file part of the AWS SDK.
public static function factory($config = array())
{
$exceptionParser = new S3ExceptionParser();
// Configure the custom exponential backoff plugin for retrying S3 specific errors
if (!isset($config[Options::BACKOFF])) {
$config[Options::BACKOFF] = static::createBackoffPlugin($exceptionParser);
}
$config[Options::SIGNATURE] = $signature = static::createSignature($config);
...
The Options-class is the Aws\Common\Enum\ClientOptions. If you look at it it defines a lot of constants like this:
const SIGNATURE = 'signature';
const BACKOFF = 'client.backoff';
I call the factory function in the following way:
$s3 = S3Client::factory(_PS_ROOT_DIR_.'/override/aws/aws-config.php');
My aws-config.php file looks like this:
<?php
return array(
'includes' => array('_aws'),
'services' => array(
'default_settings' => array(
'params' => array(
'key' => 'XXXXXXXXXXX',
'secret' => 'XXXXXXXXXXX',
'region' => 'eu-west-1'
)
)
)
);
?>
Any ideas? I installed the PHP SDK with Composer, so I'd expect any dependancies to be installed.
The argument to S3Client::factory() is supposed to be an array. You're giving it a filename that contains PHP code to return the array, but S3Client doesn't run the file. Try changing the file to:
<?php
$s3options = array(
'includes' => array('_aws'),
'services' => array(
'default_settings' => array(
'params' => array(
'key' => 'XXXXXXXXXXX',
'secret' => 'XXXXXXXXXXX',
'region' => 'eu-west-1'
)
)
)
);
?>
Then your main program can do:
require(_PS_ROOT_DIR_.'/override/aws/aws-config.php');
$s3 = S3Client::factory($s3options);

How to migrate entity from XML to Drupal 7 using migrate module

I have created a class using migrate module but I am unable to migrate entities. my class codes are below please check it and tell me whats the problem with it??
<?php
class ItemOrderXMLMigration extends XMLMigration {
public function __construct() {
parent::__construct(MigrateGroup::getInstance('OrderFeed'));
$this->description = t('Migrate entity from XML file');
//$this->softDependencies = array('WineFileCopy');
$fields = array(
'Number' => t('Number'),
'Date' => t('Date'),
'SubTotal' => t('Sub Total'),
'Discount' => t('Discount'),
'ShippingCharges' => t('Shipping Charges'),
'ShippingChargesDiscount' => t('Shipping Charges Discount'),
'NumItems' => t('NumItems'),
'VATPercentage' => t('VAT Percentage'),
'CurrencyCode' => t('Currency Code'),
'PaymentTypeDesc' => t('Payment Type Desc'),
'OrderState' => t('Order State'),
);
$this->map = new MigrateSQLMap($this->machineName,
array(
'Number' => array(
'type' => 'varchar',
'length' => 225,
'not null' => TRUE,
)
),
MigrateDestinationEntityAPI::getKeySchema('entity_example_basic','first_example_bundle')
);
$xml_folder = DRUPAL_ROOT . '/' . drupal_get_path('module', 'products_import') . '/xml/';
$items_url = $xml_folder . 'OrderFeed.xml';
$item_xpath = '/Orders/Item'; // relative to document
$item_ID_xpath = 'Number'; // relative to item_xpath and gets assembled
// into full path /producers/producer/sourceid
$items_class = new MigrateItemsXML($items_url, $item_xpath, $item_ID_xpath);
$this->source = new MigrateSourceMultiItems($items_class, $fields);
$this->destination = new MigrateDestinationEntityAPI('entity_example_basic','first_example_bundle');
$this->addFieldMapping('field_number', 'Number')
->xpath('Number');
$this->addFieldMapping('field_subtotal', 'SubTotal')
->xpath('SubTotal');
$this->addFieldMapping('field_discount', 'Discount')
->xpath('Discount');
//$this->addUnmigratedDestinations(array('weight'));
}
}
?>
When I import it I got the save error message for all entities: Creating default object from empty value File /var/www/mig/migration/sites/all/modules/migrate_extras/entity_api.inc, line 227
Try the latest or updated migrate module https://www.drupal.org/project/migrate. I think you were using old one which were having some issues to migrate entities.
Why don't you try with a feed importer (Feeds module) using XPath parser module?. It's really easy, and you can use both an uploaded file or a source URL.

AWS dynamodb PHP 'Command was not found matching Update_table'

I working on a web application and since a lot of read and write action happening in the amazon dynamodb table am facing a provisionthroughput error. Thinking of using a Update table I used below code but facing error. This error is not mentioned in error handling chart of dynamobb.
<?php
use Aws\DynamoDb\DynamoDbClient;
$dynamoDB = DynamoDbClient::factory(array(
'key' => '',
'secret' => '',
'region' => Region::US_WEST_1
));
####################################################################
# Updating the table
// $dynamodb = new AmazonDynamoDB();
echo PHP_EOL . PHP_EOL;
echo "# Updating the \"${dynamo_db_table}\" table..." . PHP_EOL;
$up = $dynamoDB->Update_table(array(
'TableName' => $dynamo_db_table,
'ProvisionedThroughput' => array(
'ReadCapacityUnits' => 39,
'WriteCapacityUnits' => 37
)
));
$table_status = $dynamoDB->describe_table(array(
'TableName' => $dynamo_db_table
));
// Check for success...
if ($table_status->isOK())
{
print_r($table_status->body->Table->ProvisionedThroughput->to_array()->getArrayCopy());
}
else
{
print_r($table_status);
}
$count = 0;
do {
sleep(5);
$count += 5;
$response = $dynamoDB->describe_table(array(
'TableName' => $table_name
));
}
while ((string) $response->body->Table->TableStatus !== 'ACTIVE');
echo "The table \"${table_name}\" has been updated (slept ${count} seconds)." . PHP_EOL;
?>
I am facing below error:
# Updating the "tablename" table...
Fatal error: Uncaught exception 'Guzzle\Common\Exception\InvalidArgumentException' with message 'Command was not found matching Update_table' in /home/phretscl/public_html/RETS/vendor/guzzle/guzzle/src/Guzzle/Service/Client.php:117 Stack trace: #0 /home/phretscl/public_html/RETS/vendor/guzzle/guzzle/src/Guzzle/Service/Client.php(94): Guzzle\Service\Client->getCommand('Update_table', Array) #1 /home/phretscl/public_html/RETS/vendor/aws/aws-sdk-php/src/Aws/Common/Client/AbstractClient.php(103): Guzzle\Service\Client->__call('Update_table', Array) #2 /home/phretscl/public_html/RETS/file.php(97): Aws\Common\Client\AbstractClient->__call('Update_table', Array) #3 /home/phretscl/public_html/RETS/file.php(97): Aws\DynamoDb\DynamoDbClient->Update_table(Array) #4 {main} thrown in /home/phretscl/public_html/RETS/vendor/guzzle/guzzle/src/Guzzle/Service/Client.php on line 117
The code you are using is not correct. From the error message, I can tell you are using version 2.x of the AWS SDK for PHP, but the code you using from ############ line down looks like it is meant for version 1.x of the AWS SDK for PHP. The error is being thrown, because you are not calling the DynamoDbClient::updateTable() method correctly.
You should checkout the AWS SDK for PHP User Guide, particularly the page about DynamoDB, which has a code sample for UpdateTable.
EDIT w/ regards to the comments: If this is a long running process, you should use the Aws\Common\Aws way of instantiating the client, since it retains and reuses the client objects it creates. Replace you DynamoDbClient::factory(...) code with this:
use Aws\Common\Aws;
$aws = Aws::factory(array(
'key' => '...',
'secret' => '...',
'region' => Region::US_WEST_1
));
$dynamoDB = $aws->get('dynamodb');
You should provide the credentials like this
Also, the region should be like this 'region'=>'us-east-1'
$DDBClient = DynamoDbClient::factory([
'region'=>'us-east-1',
'version' => 'latest',
'credentials' => [
'key' => 'XXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXX'
]
,'scheme' => 'http' // Use this if you don't have HTTPS
//, 'debug' => true
]);

Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /home1/gcc/public_html/university/core/init.php on line 22 [duplicate]

This question already has answers here:
PHP anonymous function causes syntax error on some installations
(3 answers)
PHP, Parse error: syntax error, unexpected T_FUNCTION [duplicate]
(1 answer)
Closed 9 years ago.
Run the code in local host wamp, but when i uploaded to the server i got this error. Below is my code
<?php
session_start();
$GLOBALS['config'] = array(
'mysql' => array(
'host' => 'localhost',
'username' => 'root',
'password' => '',
'db'=> 'database name'
),
'remember' => array(
'cookie_name' => 'hash',
'cookie_expiry' => 604800
),
'session' => array(
'session_name' => 'user',
'token_name' => 'token',
'secure' => rand(1000, 9999)
)
);
spl_autoload_register(function($class) { // error here
require_once 'classes/' .$class. '.php';
});
It seems because you are running on an old PHP version (older than PHP 5.3), anonymous function are seen as syntax errors. PHP implements callbacks as string. You can define the function normally, and pass a name of the function instead.
function custom_autoloader($class) {
// your code..
}
spl_autoload_register('custom_autoloader');
Your PHP version is not supporting anonymous function. You need at least 5.3.0
You can check your current version eg. using phpinfo().

Categories