Suppose a PHP script uses methods of class A and then regenerates new source code of class A.  If class A is already declared, does PHP provide a method to undeclare class A so that I may re-require the newly created source of class A?  By 'already declared' I mean, that the source of a class has been parsed, thus the class name is defined and bound to the class definition.  Update 2014-02-22   does provide the . Without using RunKit, there doesn't seem to be a method to undeclared / undefine a class.
123261
Is there any way to redefine a class or some of its methods without using typical inheritance? For example: class third_party_library {     function buggy_function() {         return 'bad result';     }     function other_functions(){         return 'blah';     } }  What can I do to replace buggy_function()? Obviously this is what I would like to do class third_party_library redefines third_party_library{     function buggy_function() {         return 'good result';     }     function other_functions(){         return 'blah';     } }  This is my exact dilemma: I updated a third party library that breaks my code. I don't want to modify the library directly, as future updates could break the code again. I'm looking for a seamless way to replace the class method. I've found this  that says it can do it, but I'm wary as it's 4 years old. EDIT: I should have clarified that I cannot rename the class from third_party_library to magical_third_party_library or anything else because of framework limitations. For my purposes, would it be possible to just add a function to the class? I think you can do this in C# with something called a &quot;partial class.&quot;
101821
while making a call from php i am getting the error      Attempt to de-reference a null object Class.Demo.Insert:   What is problem in my webservice?  global class Ctest{     global class RequestClass{         webservice String accName;     }      webservice static void   cInsert(RequestClass req){         Account a1 = new Account();         a1.Name = req.accName;         insert a1;     } }   And Our Php Code Is  require_once('salesforceAPI/soapclient/SforceEnterpriseClient.php'); require_once('salesforceAPI/soapclient/SforceHeaderOptions.php');  $sfdc = new SforceEnterpriseClient(); $SoapClient = $sfdc-&gt;createConnection('enterprise.wsdl.xml');  $loginResult = false;  $loginResult = $sfdc-&gt;login(USER, PASSWORD . SECURITY_KEY);  $parsedURL = parse_url($sfdc-&gt;getLocation()); define("_SFDC_SERVER_", substr($parsedURL['host'], 0, strpos($parsedURL['host'], '.'))); define("_WS_NAME_", 'salesforceAPI/Ctest'); define("_WS_WSDL_", _WS_NAME_ . '.xml'); define("_WS_ENDPOINT_", 'https://' . _SFDC_SERVER_ . '.salesforce.com/services/wsdl/class/' . _WS_NAME_); define("_WS_NAMESPACE_", 'http://soap.sforce.com/schemas/class/' . _WS_NAME_);  $client = new SoapClient(_WS_WSDL_); $sforce_header = new SoapHeader(_WS_NAMESPACE_, "SessionHeader", array("sessionId" =&gt; $sfdc-&gt;getSessionId())); $client-&gt;__setSoapHeaders(array($sforce_header));  $method = $client-&gt;__getFunctions();  $wsParams = array('accName' =&gt; 'XXXXXXX');  $client-&gt;cInsert($wsParams)
14535
I am looking for the definition of when I am allowed to do forward declaration of a class in another class's header file:  Am I allowed to do it for a base class, for a class held as a member, for a class passed to member function by reference, etc. ?
9286
Delphi (and probably a lot of other languages) has class helpers. These provide a way to add extra methods to an existing class. Without making a subclass.  So, what are good uses for class helpers?
36147
The following method does not work because the inner block declares a variable of the same name as one in the outer block. Apparently variables belong to the method or class in which they are declared, not to the block in which they are declared, so I therefore can't write a short little temporary block for debugging that happens to push a variable in the outer scope off into shadow just for a moment:  void methodName() {   int i = 7;   for (int j = 0; j &lt; 10; j++) {     int i = j * 2;   } }   Almost every block-scoped language I've ever used supported this, including trivial little languages that I wrote interpreters and compilers for in school.  Perl can do this, as can Scheme, and even C.  Even PL/SQL supports this!  What's the rationale for this design decision for Java?  Edit: as somebody pointed out, Java does have block-scoping.  What's the name for the concept I'm asking about?  I wish I could remember more from those language-design classes. :)
20526
It is to my understanding that one should use a forward-class declaration in the event ClassA needs to include a ClassB header, and ClassB needs to include a ClassA header to avoid any circular inclusions. I also understand that an #import is a simple ifndef so that an include only happens once.  My inquiry is this: When does one use #import and when does one use @class? Sometimes if I use a @class declaration, I see a common compiler warning such as the following:     warning: receiver 'FooController' is a forward class and corresponding @interface may not exist.   Would really love to understand this, versus just removing the @class forward-declaration and throwing an #import in to silence the warnings the compiler is giving me.
9451
I've been looking at the JMS API from J2EE and found a strange behavior where certain methods that are declared in an interface (e.g., createQueue in Session) are declared again in the subinterfaces such as QueueSession, and with identical documentation.  Since an subinterface "inherits" all the method declarations of the interface it inherits, and since the JavaDoc tool has no problem sorting out the JavaDocs of the subinterface and creating an "inherited operations" list, I can't figure out what this achieves.  The only think of is that initially the call was in Session, and then moved to QueueSession when the specific subclass was created, though then I would have expected to see something in the documentation of the upperclass. But this is just conjecture.  So the question is: Is there a convincing reason to redeclare a method in a subinterface?
46370
I am trying to add a body class to my site in template.php based on whether or not a node is published or not. I had a look around here and on drupal.org and pieced together some code but I am getting an error. Here is what I have tried so far:  function responsive_process_html(&amp;$variables) {    if ($node-&gt;status == 1){         //$variables['#attributes']['class'][] = 'pub';         $variables['classes_array'][] = 'published';     }      else {         $variables['classes_array'][] = 'not-published';     } }   ... but I am getting this error:  Notice: Undefined variable: node in responsive_process_html() (line 37 of /sites/all/themes/responsive/template.php). Notice: Trying to get property of non-object in responsive_process_html() (line 37 of /sites/all/themes/responsive/template.php).   I also tried $variables['#attributes']['class'][] = 'published'; instead of $variables['classes_array'][] = 'published'; but it made no difference.
55703
I want to write several classes, most of them will use KOMA classes as base class.  However I stumbled upon the problem that some options (mainly concerned with layout) are not processed if given in the wrapper class:    \begin{filecontents}{test.cls}     \ProvidesClass{test}[2015/01/01]     \DeclareOption*{\PassOptionsToClass{\CurrentOption}{scrartcl}}     \ProcessOptions\relax     \LoadClass[paper=a5]{scrartcl}   \end{filecontents}  \documentclass{test}  \usepackage{blindtext}  \begin{document}   \section{Test}   \blindtext \end{document}   This results in   LaTeX Warning: Unused global option(s):     [paper=a5]  If i give the option as \documentclass[paper=a5]{test} it is used correctly, because I pass the options to scrartcl. However I want to change the defaults for the layout.   How can I achieve this?
31700
After you define a command using \newcommand, is it possible to undefine it?  My motivation is that I'm writing a thesis, where each chapter is in a separate source file. Some chapters define their own commands that are used nowhere else, so I'd like them to be visible only within that chapter.   I'd therefore like to be able to do something like:  \chapter{Some Chapter} \newcommand{foo}{...} ... % chapter body \forgetcommand{foo} % end of chapter   Is there anything like the fictitious \forgetcommand macro above?
24511
In JavaScript nested functions are very useful: closures, private methods and what have you..  What are nested PHP functions for? Does anyone use them and what for?  Here's a small investigation I did  &lt;?php function outer( $msg ) {     function inner( $msg ) {         echo 'inner: '.$msg.' ';     }     echo 'outer: '.$msg.' ';     inner( $msg ); }  inner( 'test1' );  // Fatal error:  Call to undefined function inner() outer( 'test2' );  // outer: test2 inner: test2 inner( 'test3' );  // inner: test3 outer( 'test4' );  // Fatal error:  Cannot redeclare inner()
119696
In Java you can define a new class inline using anonymous inner classes. This is useful when you need to rewrite only a single method of the class.  Suppose that you want create a subclass of OptionParser that overrides only a single method (for example exit()). In Java you can write something like this:  new OptionParser () {      public void exit() {         // body of the method     } };   This piece of code creates a anonymous class that extends OptionParser and override only the exit() method.  There is a similar idiom in Python? Which idiom is used in these circumstances?
41834
Has anybody used a good obfuscator for PHP? I've tried some but they don't work for very big projects. They can't handle variables that are included in one file and used in another, for instance.  Or do you have any other tricks for stopping the spread of your code?
45128
Lets say I'm building a base class which will be extended upon by the children class. So a base class is called Base and children can be Child1, Child2, etc.  In the base class's constructor, how can i get the value of Child1/Child2?  This is all using PHP
60178
In Java, is there any way to use the JDK libraries to discover the private classes implemented within another class? Or do I need so use something like asm?
18958
How do I lock compiled Java classes to prevent decompilation?  I know this must be very well discussed topic on the Internet, but I could not come to any conclusion after referring them.  Many people do suggest obfuscator, but they just do renaming of classes, methods, and fields with tough-to-remember character sequences but what about sensitive constant values?  For example, you have developed the encryption and decryption component based on a password based encryption technique. Now in this case, any average Java person can use  to decompile the class file and easily retrieve the password value (defined as constant) as well as  and in turn can decrypt the data by writing small independent program!  Or should such sensitive components be built in native code (for example, VC++) and call them via ?
121834
How are callbacks written in PHP?