Simple-LInked Error - api

I have placed the simple linkedin class on my server and added my api keys etc, however when i call the demo page i get the following error:
Parse error: syntax error, unexpected T_FUNCTION in /home/mycv/public_html/dev/linkedin_3.2.0.class.php on line 259
this is the code for the area around line: 259
if(is_array($http_code_required)) {
array_walk($http_code_required, function($value, $key) {
if(!is_int($value)) {
throw new LinkedInException('LinkedIn->checkResponse(): $http_code_required must be an integer or an array of integer values');
}
line 259: seems to refer to the second line starting with array walk.
Thanks

Anonymous functions only became available in PHP 5.3.0. Line 259 above uses an anonymous function, so that would explain the error if your version pre-dates support.

Just make the anonymous function as a named function and call it in the checkResponse function:
function **innerfunction**($value, $key) {
if(!is_int($value)) {
throw new LinkedInException('LinkedIn->checkResponse(): $http_code_required must be an integer or an array of integer values');
}
}
private function checkResponse($http_code_required, $response) {
// check passed data
if(is_array($http_code_required)) {
array_walk($http_code_required, **innerfunction**($value, $key));
}
}

Related

How to handle simple error in Kotlin function Android

I'm having trouble handling error in the following function. I'm basically new to Kotlin. Here's my RevenueCat Login Code and I want to handle ::error in this code:
Purchases.sharedInstance.logInWith(
myUserID,
::error // <- How to handle this? I want to retrieve error Code and Error Message.
)
{ customerInfo, created ->
// Handle Successful login here
}
Here's the code behind the function (within RevenueCat SDK)
#Suppress("unused")
fun Purchases.logInWith(
appUserID: String,
onError: (error: PurchasesError) -> Unit = ON_ERROR_STUB,
onSuccess: (customerInfo: CustomerInfo, created: Boolean) -> Unit
) {
logIn(appUserID, logInSuccessListener(onSuccess, onError))
}
The double colon in ::error is a function reference. It is basically a reference to the function error().
And from your logInWith() function, we have onError: (error: PurchasesError) -> Unit = ON_ERROR_STUB, meaning that the function should take PurchasesError as input parameter and does not need to return.
So we can derive a function as the following:
fun error(error: PurchasesError) {
// And you can do something with the error here
}
I solved it like this:
Purchases.sharedInstance.logInWith(
myUserID,
onError = { error ->
// Handle error here
}

How to write custom errors and return messages with error keyword Solidity

I tried to make a custom error but it doesn't return a message to revert
How could I make it return a message?
/// custom error
error MyCustomError(address _address);
if user { revert MyCustomError({address: msg.sender}) }
I got this error
Runtime error: revert
There are two errors:
1- if statement should be inside a function
2- when you defined the custom error,you defined the named parameter as _address
contract Test {
address public user;
/// custom error
error MyCustomError(address _address);
function revertError() public view {
// I just had to pass a valid condition. address(0)=0x0000000000000000000000000000000000000000
// if(user) would give this error: "Type address is not implicitly convertible to expected type bool"
if(user!=address(0))
{
revert MyCustomError({_address: msg.sender});
}
}
}

Mockk matching and overloaded function withArg

Hello I am trying to find a way to match an overloaded function inside of the verify using withArg
The doc doesnt really point this out
every { getResponse.Ids } returns listOf(121212L)
assert( client.getExtIds(Ids) )
verify {
client.getExtIdsCall().call(
withArg {
assertEquals(GetExtIdsRequest.builder()
.withIds("foo")
.withType("bar")
.build().hashCode(), it.hashCode()
)
}
)
}
Something like above. But unfortunately I cant because the client.getExtIdsCall().call() accepts two different types of objects. One of which has the hashCode I want. So the it can not be referred correctly to call the hashCode function
You can resolve this by explicitly specifying the type parameter of function withArg, e.g. if you want your parameter to be a Long, you can write:
withArg<Long> { ... }

Function with return type and "use" keyword

How can you create a function that specifies both the return type and the external variables to use?
Are the examples below wrong or is it not supported (yet)?
<?php
$arr = ['test' => 'value'];
function test1() use ($arr) : string { // Line 5
return $arr['test'];
}
function test2() : string use ($arr) {
return $arr['test'];
}
The error is:
Parse error: syntax error, unexpected 'use' (T_USE), expecting '{' in [PATH]\index.php on line 5
You can run the code here.
As answered by Adam Cameron in the comments, the problem is that the use language construct only applies to closures, not to all functions. Thus, using it on normal functions makes no sense and is as such not understood by the parser.
When the function in the example code would have been a closure, everything would have worked.
$arr = ['test' => 'value'];
$fn = function() use ($arr) : string {
return $arr['test'];
};
echo($fn()); // outputs 'value'
You can run the code here.
Note that your first attempt is correct: first the use statement, then the return type declaration. Trying to reverse these two will result in a parse error.

Mapping IOKit IOReturn error code to String

When I get error 0x10, I want to be able to make sense of that error code. Looking up IOReturn.h and mach/error.h is not particularly convenient. I was lost when I got 0x22 error code. This is really silly question but is there a function like error2String which can map IOReturn error code to String that describes the error ?
You can use the mach_error_string standard foundation function to do this.
Eg. in Swift:
func krToString (_ kr: kern_return_t) -> String {
if let cStr = mach_error_string(kr) {
return String (cString: cStr)
} else {
return "Unknown kernel error \(kr)"
}
}
Code running in the kernel can use IOService::stringFromReturn(...)