NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Setting type of global objects


Joined: 21 Oct 2004
Posts: 81
Location: UK
Reply with quote
I have a project where I have a few objects which are global, ie. many functions include them with the global keyword. For example, this sort of this frequently occurs:

Code:
$obj = new MyClass;

function getData() {
  global $obj;
  $obj->


However, PhpED doesn't know what class $obj is within the function and if I hit Ctrl+Space to get the list of properties/methods, it gives an error "Failed to identify type of $obj local variable". Is there any way to get PhpED to recognise this? It can get even more confusing of course, if instead of "$obj = new MyClass;", it is "$obj =& CreateMyClass(); // returns MyClass object". I'd be perfectly happy with some sort of comment around the global statement, like can be done with functions through @desc. I see there is a @global but I can't figure out how to use it or if it does what I'm looking for.
View user's profileFind all posts by QuboidSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8342
Reply with quote
Thanks for the report.
Fix will come with build 4522:

View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 21 Oct 2004
Posts: 81
Location: UK
Reply with quote
Wow, thanks, that was quick.

What about functions that return objects? I'd imagine it's pretty hard to determine the type of object, especially as it could be dependant on runtime conditions. Also, what if the object is created in another file?
View user's profileFind all posts by QuboidSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8342
Reply with quote
it does not really matter if new is called in another file, what does matter is how the resuling object is "delivered" to the point.
Regarding objects returned as a function or method result, it is supported while you keep clear code and it's clear what class instance is created by new, otherwise you have to add typehint to "suggest" code insight the object type.
If you ever encounter anything that might work but does not, feel free to submit code sample.
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 21 Oct 2004
Posts: 81
Location: UK
Reply with quote
What do you mean by adding a typehint? Is that a PHPDoc comment? I can't figure out how to use these and I can't find any documentation (not even on the PHPDoc site, pretty strange for a documentation program not to have decent documentation!).
View user's profileFind all posts by QuboidSend private message


Joined: 21 Oct 2004
Posts: 81
Location: UK
Reply with quote
I'm still having trouble with this (build 4523), it is at least partially functioning but there are flaws. For example:

Code:
$obj = NULL;

function getData() {
  global $obj;

  $obj = new MyClass();
  $obj->


This doesn't work (can't determine type of local variable $obj), however if I remove the global line, it has no problem determining that $obj is a MyClass().
View user's profileFind all posts by QuboidSend private message
Setting type of global objects
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic