top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

Class auto assigning to Variable in PHP

–1 vote
65 views

I have a situation where, for some unknown reason, where each class that finishes its __contruct{} function, that class gets automatically assigned to a variable - other than the variable I specify.

Conceptually:

class Hello { private $_world = 'World'; __construct(){} }
$clsHello = new Hello();
echo 'The variable $hello is '.gettype($hello)."n".print_r($hello,true);

Output:

The variable $hello is object
Hello Object
(
 [_world:Hello:private] => World
)

There is no statement in my application that assigns an instance of the class to another variable, the name being a lowercase variant of the class name.

Would there be a PHP function that would do this as a side-effect?

I am more interested in learning what is happening as opposed to rolling back to a previous version. (A backup copy functions fine. A file compare does not reveal any likely suspects.)

posted Aug 7, 2013 by Sheetal Chauhan

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

This isn't even valid PHP

 $ php -a
Interactive shell

php > class Hello { private $_world = 'World'; __construct(){} }
PHP Parse error: syntax error, unexpected '__construct' (T_STRING),
expecting function (T_FUNCTION) in php shell code on line 1
answer Aug 7, 2013 by Jai Prakash
Similar Questions
0 votes

I have a client where their next auto-increment number just jumped from 2300 to ********** for reasons not understood. They want it set back.

Options such as dropping the primary key and rebuilding the index is NOT possible -- this is a relational table thing. So, is there a way (programmatically) to set the next number in an auto-increment?

Something like:

alter table abc auto_increment = 2301;

Any ideas of why this happened?

0 votes

I've tried the following code but the $call variable is not available in the pcntl_fork child. Searching the web, I've found posts that claim that all variables defined before pcntl_fork are copied to the child. I've also found posts that claim that no variables are passed/copied to the child. So, which of them is true and how should I correct my code to make it work?

 $call = str_replace('@@', '&', $_GET['call']);

 if ($pid = pcntl_fork())
 {
     $previousCalls=file("calls.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
     if (!in_array($call, $previousCalls))
     {
         file_put_contents("calls.txt", $call."\n", FILE_APPEND);
     }
 }
 else
 {
     function displayUrl($url)
     {
         $ch = curl_init($url);
         curl_setopt ( $ch, CURLOPT_HEADER, 1);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $curlResult = curl_exec($ch);
         curl_close($ch);
         list($headers,$content) = explode("\r\n\r\n",$curlResult,2);
         foreach (explode("\r\n",$headers) as $hdr)
         {
             if ($hdr != 'Transfer-Encoding: chunked')
             {
                 header($hdr);
             }
         }
         echo $content;
     }
     displayUrl($call);
 }
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...