I have consistent difficulty using any client service method that is not explicitly exampled somewhere. Despite following the docs and even reading the sourcecode, The class or method names I come up with following the scheme are never right.
The documentation at Packagist (see 'Making Requests") says the client library classes are autogenerated from the Google endpoints, which agrees with the description in the library's docs on Github that say the pattern for accessing methods should be "$service->resource->method(args)".
So why the following?
// works:
// I get a countable object of active classrooms owner by the specified id
$response = $this->ClassroomService->courses->listCourses([
'courseStates' => 'ACTIVE',
'teacherId' => 'me']);
// works:
// I get an instance of the single classroom's object containing lots of meta data
$response = $this->ClassroomService->courses->get( $id );
// does not work:
// 500 error, obj has no such method
$response = $this->ClassroomService->topics->listCoursesTopics( $id );
According to the API Explorer all three should be fine.
What am I missing about using client service objects?
Edit
Ultimately I determined the resource in my example to be 'courses_topics'; the method was correct per the docs. Thanks for the idea #ebram.
The question remains how the methods are named though. courseWork is my next challenge and it does not fit the the naming pattern of topics.
There is no topics member of ClassroomService.
The member is named courses_topics.
This is documented in the "Properties summary" at the bottom of the Classroom documentation.
Your code should look like this:
$response = $this->ClassroomService->courses_topics->listCoursesTopics( $id );
The documentation for Google_Service_Classroom_CoursesTopics_Resource does incorrectly give sample code where the member is named ->topics.
Given that API documentation is generated from source, but sample code is (generally) written by hand, I'll assume the API documentation is correct and the sample code is incorrect. I'd file a documentation-bug with Google.
Update:
I looked at the PHP source code for Google_Service_Classroom in GitHub and verified that the property is named courses_topics instead of topics, so in conclusion: the sample code is wrong.
What's also interesting is the resource-type in the actual source-code is Google_Service_Classroom_Resource_CoursesTopics but the documentation refers to it as Google_Service_Classroom_CoursesTopics_Resource - so that documentation is definitely wrong.
I feel a bit silly, but I have no clue how to parse the objects that Google returns from their API in PHP, can someone shine a light on it?
So for instance, if I request:
print_r($job->getState());
I get this:
Google\Cloud\Scheduler\V1\HttpTarget Object
(
[uri:Google\Cloud\Scheduler\V1\HttpTarget:private] => http://example.com/cron-check.php
[http_method:Google\Cloud\Scheduler\V1\HttpTarget:private] => 1
[headers:Google\Cloud\Scheduler\V1\HttpTarget:private] => Google\Protobuf\Internal\MapField Object...
So how in the world do I get the uri value out of this object?
Googling the Object you're receiving in response, I found the source code for it:
https://github.com/googleapis/google-cloud-php/blob/master/Scheduler/src/V1/HttpTarget.php
Looking at this, there appears to be a simple getter method for the URI property. Try:
$job->getState()->getUri();
We're randomly getting some very strange error logs. They don't happen on every page hit, even with the same parameters/actions/etc, and they don't seem repeatable, each one is different in its crash location, and context. But almost all have incorrect __PHP_Incomplete_Class_Name as the cause.
One such error is:
main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "LoginLogging" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition
The problem being, there is no "LoginLogging" class. The object it's referring to was of type ScormElement when it was saved into the session.
Doing a dump of the variable gives:
__PHP_Incomplete_Class::__set_state(array(
'__PHP_Incomplete_Class_Name' => 'LoginLogging',
'intUserId' => '64576',
'__intUserId' => '64576',
'intScormId' => '665',
'__intScormId' => '665',
'intScoId' => '9255',
'__intScoId' => '9255',
'strElement' => 'cmi.core.lesson_location',
'__strElement' => 'cmi.core.lesson_location',
'strValue' => '1',
'dttTimeModified' => QDateTime::__set_state(array(
'blnDateNull' => false,
'blnTimeNull' => false,
'strSerializedData' => '2011-08-31T08:05:22-0600',
'date' => '2011-08-31 08:05:22',
'timezone_type' => 1,
'timezone' => '-06:00',
)),
'__strVirtualAttributeArray' => array (),
'__blnRestored' => true,
'objUser' => NULL,
'objScorm' => NULL,
)
All the properties are retained correctly, and match the class definition for ScormElement. But the class name is wrong. There is no class named LoginLogging.
What is causing this and how do we fix it???
Edit: This is just an example. Other errors are very similar in structure, but affect other class types, and have different incomplete names. However, ALL incomplete names have the same string length of the correct class name.
Edit 2011-10-27: I'm still seeing these error logs, and have had no success in finding a solution. Any help would be appreciated.
PHP 5.3.3, APC, default session handler.
As written in the quote in your question __PHP_Incomplete_Class_Name is a special class name in PHP that is used whenever the class definition could not be found when unserializing (unserialize()).
It's suggested to either ensure the class definition is available or to provide some autoloading for the missing class.
You commented that PHP is looking for the wrong classname here:
wrong: LoginLogging
right: ScormElement
It's hard to say with the information given why the classname is being changed on serialization/unserialization. The information you've given (especially the dump) in your question is incomplete.
So the options are limited to some general suggestions:
You could inspect the serialized string which classname is given in there so you could at least say if it happens with serialization or unserialization. You can easily inspect serialized data with the Serialized PHP Library which has a text-dumper for debug purposes.
Additionally there is the unserialize_callback_func Ini-Directive you can use to further trace the problem.
<?php
$serialized_object='O:1:"a":1:{s:5:"value";s:3:"100";}';
// unserialize_callback_func directive available as of PHP 4.2.0
ini_set('unserialize_callback_func', 'mycallback'); // set your callback_function
function mycallback($classname)
{
// just include a file containing your classdefinition
// you get $classname to figure out which classdefinition is required
}
As you write the problem does not occur any longer, I suspect that at some point the serialization on your site was broken storing invalid data. Which framework/libraries/application are you using? Which component takes care about serialization?
If your trying to access a property method of an object or serialized value you've stored in a $_SESSION variable and you included the class after calling session_start() try including the class before calling session_start();
This happens when we try to initialize the session before loading the class definitions for the object we are trying to save into the session.
you can use simply json methods in PHP
json_encode that array and again json_decode that array and save it in a variable and than print that variable. you will get a simple array.
eg.
$array = array(); // this is your array variable to whom you are trying to save in a session
$encode = json_encode($array);
$decode = json_decode($encode);
echo '<pre>';
print_r($decode);
it will work surely.
Are you, by any chance, using some opcode cache (e.g. APC, XCache) or some debugger? They sometimes cause weird things to happen. If there isn't and never was a LoginLogging class in your project, but yours is not the only project on the server, I would bid on the cache.
To include the class before the session_start() works fine for me. =)
Hakre's suggestion to look at session_write_close led me to what appears to be a reliable fix:
register_shutdown_function('session_write_close');
This forces the session to be written out before any memory cleanup and class unloading occurs. This is important due to a change in PHP that can result in a race condition between APC removing class references and PHP writing out the session data: http://news.php.net/php.internals/46999
When you try to unserialize a variable, php must know the structure of the object. Try to include your class before unserialize. Which class? the one that holds those properties shown in your code. include('pathtoyourclass/classname.php') or include_once('pathtoyourclass/classname.php').
Good luck!
I use this function to solve this problem
$user = $_SESSION['login'];
$auth_user= fixObject($user);
function fixObject(&$object) {
if (!is_object($object) && gettype($object) == 'object')
return ($object = unserialize(serialize($object)));
return $object;
}
It is the serialization issue in your code.It may be your code for some reason could not initialize the object and in next part of your code tries to convert that object to string or some other data type.
Just inspect your code, properly initialize your objects.
Check if you are using serialize()/unserialize() method.
Are you receiving this serialized object from a service/stream or reading it from a file? I've seen it happen in a client-server setting the client side object and the server side objects differ very slightly... maybe have a property that the other doesn't have. This also happens when you serialize an object, save it to file, then refactor code that removes a class and then try's to deserialize the object.
Then when it gets deserialized and tries to instantiate the needed classes they don't exist.
The error is clear and straightforward, you're creating a object for which the class has not been loaded.
I'd do a string search on your code, find where the needed class is located, and make a simple autoloader (or just a raw include/require) of the file. Just get the class it needs loaded somehow.
If the class really doesn't exist anywhere, try checking earlier revisions (I'm assuming you have version control of some type) for existence of the class. If you're deserializing an object generated by another system check that system out as well.
I'm trying to use Zend_Soap_Client to communicate with an ASP.net web service. Here's my client call:
$client = new Zend_Soap_Client(null, array(
'location' => 'http://example.com/service.asmx',
'uri' => 'http://example.com/'
));
$user = new UserDetail();
$result = $client->UserDetails($user);
However this always gives me the error:
System.NullReferenceException: Object reference not set to an instance of an object. at Service.UserDetails(UserDetail UserDetail)
some googling revealed that this is quite a common problem. The most common solution seemed to be to pass the parameters as an array, so I tried:
$result = $client->UserDetails(array('UserDetail' => $user));
but this gave the same error. I also tried passing the params as a stdClass object, nesting the array in another with 'params' as the key, and a few other things but the error is always the same.
I have the ASP code for the web service itself, the relevant method is:
public Result UserDetails(UserDetail UserDetail) {
[some stuff]
Hashtable ht = new Hashtable();
ht = UserDetail.GenerateData();
}
the error is caused by the GenerateData() call.
I assume the UserDetails method is getting null instead of my object as the parameter, but I'm not sure how I should be calling the method, or how I can debug this further. The majority of the Zend_Soap_Client examples I've found seem to be using WSDL, which this service is not; not sure if that is relevant. Any help appreciated!
I eventually solved this with:
$userDetails = new UserDetails();
$userDetails->UserDetail = $user;
$client->UserDetails($userDetails);
it seems ASP.net expects (and returns) params to be nested in an object/array with the same name as the method being called.
If you have any possibility to change the asp.net code I'd suggest you try an implementation of the method UserDetails without parameters just to make sure that code isn't broken.
I would then create a consumer-method in asp.net, debug the http-request and see how the userdetail-object is serialized/broken down in array form. Then it's "just" a matter of creating a similar http request from php.
Confluence soap api defines two methods with the same name but different parameters:
Page getPage(String token, long pageId) - returns a single Page (according to the documentation the second parameter is String, but in WSDL it is long)
Page getPage(String token, String spaceKey, String pageTitle) - returns a single Page
I would need to call the method with two parameters using PHP SoapClient. In WSDL mode SoapClient insists on using the three-parameter one. In non-WSDL mode I managed to make a call with two parameters, but I cannot make the type of the second parameter to be long. How can I get the SoapClient to call getPage with two parameters with the correct types?
Here's what I've done so far:
Using SoapClient in WSDL mode...
$soapClient = new SoapClient("http://xxx/confluence/rpc/soap-axis/confluenceservice-v1?wsdl", array("trace" => TRUE));
$token = $soapClient->login(CONFLUENCE_USERNAME, CONFLUENCE_PASSWORD);
$page = $soapClient->getPage($token, $confluence_article_id);
...produces a request for the three-parameter method (only body shown)...
<SOAP-ENV:Body><ns1:getPage><in0 xsi:type="xsd:string">dkjLIx00Ap</in0><in1 xsi:type="xsd:string">24445207</in1><in2 xsi:nil="true"/></ns1:getPage></SOAP-ENV:Body>
...which causes fault:
<faultstring>com.atlassian.confluence.rpc.RemoteException: You're not allowed to view that page, or it does not exist.</faultstring>
The page with that ID does exist and I am allowed to see it, which I can confirm by making the correct kind of request with SoapUI.
Using SoapClient is non-WSDL mode...
$soapClient = new SoapClient(null, array(
"location" => "http://xxx/confluence/rpc/soap-axis/confluenceservice-v1",
"uri" => "http://soap.rpc.confluence.atlassian.com",
"trace" => TRUE));
$token = $soapClient->login(CONFLUENCE_USERNAME, CONFLUENCE_PASSWORD);
$page = $soapClient->getPage($token, $confluence_article_id);
...produces a request for the two-parameter method with incorrect type for the second parameter. When $confluence_article_id is string, the request is...
<SOAP-ENV:Body><ns1:getPage><param0 xsi:type="xsd:string">8Or94ZLqe7</param0><param1 xsi:type="xsd:string">24445207</param1></ns1:getPage></SOAP-ENV:Body>
...which returns the same fault as above:
<faultstring>com.atlassian.confluence.rpc.RemoteException: You're not allowed to view that page, or it does not exist.</faultstring>
When $confluence_article_id is integer, the request is...
<SOAP-ENV:Body><ns1:getPage><param0 xsi:type="xsd:string">y0kF4z0m9L</param0><param1 xsi:type="xsd:int">24445207</param1></ns1:getPage></SOAP-ENV:Body>
...which returns a different kind of fault:
<faultstring>org.xml.sax.SAXException: Bad types (int -> class java.lang.String)</faultstring>
If I take the request, change int to long and try it with SoapUI, it works just fine.
I have also tried to call it using __soapCall, but the results are similar:
$page = $soapClient -> __soapCall('getPage', array('in0'=>$token,'in1'=>$confluence_article_id));
There is a related PHP bug report and another one, and discussion on Atlassian forums, but none of them helped me.
So far the best suggestion has been to tweak the WSDL by removing the other getPage definition and saving it locally somewhere.
If I remember correctly you can call the function using an associative array instead ex:
//Page getPage(String token, String spaceKey, String pageTitle)
$soapClient->getPage(array("token" => $token,"spaceKey" => $spaceKey,"pageTitle" => $pageTitle));
Not tested, standard warnings apply