Getting All attributes Null

See all posts Reply

Getting All attributes Null new!
by klaudius, 11 years, 11 months ago
I had some issues to make this class working.
Nothing worked for me, no errors, no blank pages, no logs and no upload.

After some research, it appears that I all attributes were set to Null.
$handle = new upload($_FILES['image']);
var_dump($handle);

I got :
object(tools\upload)#147 (134) {
  ["version"]=> NULL
  ["file_src_name"]=> NULL
  ["file_src_name_body"]=> NULL
  ["file_src_name_ext"]=> NULL
  ["file_src_mime"]=> NULL
  ["file_src_size"]=> NULL
  ["file_src_error"]=> NULL
  ["file_src_pathname"]=> NULL
[...]

Solution : renaming the constructor from
upload($file, $lang = 'en_GB')
to
__construct($file, $lang = 'en_GB')

I work with PHP Version 5.3.10-1ubuntu3.1Reply
Re: Getting All attributes Null new!
by colin, 11 years, 11 months ago
The PHP website says:

For backwards compatibility, if PHP 5 cannot find a __construct() function for a given class, it will search for the old-style constructor function, by the name of the class. Effectively, it means that the only case that would have compatibility issues is if the class had a method named __construct() which was used for different semantics.

As of PHP 5.3.3, methods with the same name as the last element of a namespaced class name will no longer be treated as constructor. This change doesn't affect non-namespaced classes.

So it should be working, unless you added a namespace to the class.Reply
Re: Getting All attributes Null new!
by klaudius, 11 years, 11 months ago
Ok, I added a namespace, that's why. :)Reply