Re: [PHP] Unexcepted $this

2008-03-13 Thread Anup Shukla

Murat BEŞER wrote:

So what do you thing about on this thing ?



I really would like to figure out the problem.
However, my simple script to mimic your code did not throw any errors.

If you could provide some more details, maybe we can figure out the problem.

--
Regards,
Anup Shukla

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unexcepted $this

2008-03-10 Thread Anup Shukla

Murat BEŞER wrote:

Thank you Anup,

But why I getting this error ?
is this a bug ?



Its not a bug.
It has to do with operator precindence and associativity.

--
Regards,
Anup Shukla

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unexcepted $this

2008-03-10 Thread Anup Shukla

I am sorry. Please disregard my previous post.
I think i am wrong on that.

--
Regards,
Anup Shukla

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unexcepted $this

2008-03-09 Thread Anup Shukla

Murat BEŞER wrote:

I can't under stood but PHP gaves me an error:

UnExcepted $this for  || $this-getFileExtension($file) == 'jpg' 

When I removed jpg extension check it's okay... PHP script runs well.

What is the problem :)

public function loadImages($folder) {
$result = $this-filemanager-fecthFiles($folder);
$images = array();
if (sizeof($result)=1  $result !== false) {
foreach ($result as $file) {
if ($this-getFileExtension($file) == 'gif' || 
$this-getFileExtension($file) == 'png' || 
$this-getFileExtension($file) == 'jpg') {


if (
   ($this-getFileExtension($file) == 'gif') ||
   ($this-getFileExtension($file) == 'png') ||
   ($this-getFileExtension($file) == 'jpg')
) {
... rest of your code
...
}



$images[] = array('name'=$file);
}
}
}
return $images;
}




--
Regards,
Anup Shukla

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Where is FAM ?

2008-01-31 Thread Anup Shukla


Hi all,

The manual says,

XXXVII. File Alteration Monitor Functions
..
..
Note: This extension has been moved to the » PECL repository and is no 
longer bundled with PHP as of PHP 5.1.0.

..
..

But i am unable to locate it on PECL either.
Is there any way to use FAM/GAMIN with PHP ?

--
Regards,
Anup Shukla

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How can I do this -- method chaining

2008-01-30 Thread Anup Shukla

Nathan Nobbe wrote:

Actually, I don't think so. I believe constructors return void, while
the 'new' keyword returns a copy of the object.



im pretty sure constructors return an object instance:
php  class Test { function __construct() {} }
php  var_dump(new Test());
object(Test)#1 (0) {
}



AFAIK, constructor simply constructs the object,
and *new* is the one that binds the reference to the variable
on the lhs.

So, constructors return nothing.


but anyway, how could you even test that __construct() returned void
and the new keyword returned a copy of the object?  new essentially
invokes __construct() and passes along its return value, near as i can tell.

Christoph,
if you dont want to write a function in the global namespace, as suggested
in the article, Eric posted, just add a simple factory method in your class,
eg.
?php
class Test {
public static function getInstance() {
return new Test();
}

public function doSomething() {
echo __METHOD__ . PHP_EOL;
}
}
Test::getInstance()-doSomething();
?

-nathan




--
Regards,
Anup Shukla

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] potentially __sleep() bug

2008-01-30 Thread Anup Shukla

Nathan Nobbe wrote:

all,

i was playing around w/ some object serialization tonight during
further exploration of spl and i stumbled on what appears to be a
bug in the behavior of the __sleep() magic method.

here is the pertinent documentation on the method
..is supposed to return an array with the names of all variables
of that object that should be serialized.

so, the idea is, *only* the instance variables identified in the array
returned are marked for serialization.
however, it appears all instance variables are being serialized no matter what.
see the reproducible code below.  ive run this on 2 separate php5
boxes, one w/ 5.2.5, another w/ a 5.2.something..

?php
class A {
public $a1 = 'a1';
public $a2 = 'a2';
public $a3 = 'a3';

public function __sleep() {
echo __FUNCTION__ . PHP_EOL;
return array('a1', 'a2');
}
}

var_dump(unserialize(serialize(new A(;
?

this is what i get despite having marked only member variables 'a',
and 'b' for serialization.

__sleep
object(A)#1 (3) {
  [a1]=
  string(2) a1
  [a2]=
  string(2) a2
  [a3]=
  string(2) a3
}

consensus ?



To check if __sleep is proper, you should be doing
var_dump(serialize(new A()));

unserialize'ing effectively also does a __wakeup()

This should give a clearer picture

?php
class A {
public $a1 = 'a1';
public $a2 = 'a2';
public $a3 = null;

public function __construct(){
   $this-a3 = 'a3';
}

public function __sleep() {
echo __FUNCTION__ . PHP_EOL;
return array('a1', 'a2');
}
}

var_dump(unserialize(serialize(new A(;
?

__sleep
object(A)#1 (3) {
  [a1]=
  string(2) a1
  [a2]=
  string(2) a2
  [a3]=
  NULL
}

= and ==

?php
class A {
public $a1 = 'a1';
public $a2 = 'a2';
public $a3 = null;

public function __construct(){
   $this-a3 = 'a3';
}

public function __sleep() {
echo __FUNCTION__ . PHP_EOL;
return array('a1', 'a2', 'a3');
}
}

var_dump(unserialize(serialize(new A(;
?

__sleep
object(A)#1 (3) {
  [a1]=
  string(2) a1
  [a2]=
  string(2) a2
  [a3]=
  string(2) a3
}

--
Regards,
Anup Shukla

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] avoid server folder reading

2008-01-20 Thread Anup Shukla

Richard Heyes wrote:

I would like to know how to avoid (using PHP code) any user to read the
content of my website folder ?
as my website is hosted by and external company, i do not have access to
apache conf file.


If your server's default file is index.php, you could use the following 
in an index.php file:


?php
header('Location: /');
?

If it's index.html, you could use the following:

script type=text/javascript
!--
location.href = '/';
--
/script

Try the PHP version first.



Will that not result in an infinite redirection loop?
Or am i missing something very obvious !

--
Regards,
Anup Shukla

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] session_start problems with FireFox on Mac

2008-01-12 Thread Anup Shukla

Terry Calie wrote:
Hey... thanks for the replies.  I installed the headers feature that 
Richard suggested and found that no headers were output.
I started to transfer my php to another site to see if the problem 
replicated and I wasn't able to recreate the problem. 
It turns out that I require a file before the session_start that had 
one stupid character of whitespace at the end of it.  When I transferred 
the php to recreate the problem, I replaced the require call with the 
actual code - eliminating the whitespace at the end of the file, so the 
problem didn't replicate.  It took me a long time to figure out that was 
the problem.  What a killer!




You may use ob_clean() just before the header()
to get rid of the extra whitespaces.

--
Regards,
Anup Shukla

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Any way to use header() or another function to force user to top level

2008-01-12 Thread Anup Shukla

Chuck wrote:

That is exactly what I am using now but the location I am redirecting
to is loading within the div tags and at the top level of the
browser.



Are you using AJAX to load the page?

--
Regards,
Anup Shukla

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] ereg help!

2008-01-09 Thread Anup Shukla

steve wrote:

On Tuesday 08 January 2008 20:30:29 Chris wrote:

I usually use preg_* functions so here's my go:



echo preg_replace('/\.php$/', '.com', $file);


The '$' at the end makes sure it's a .php file and won't cause problems 
with files like xyz.php.txt .



(otherwise I'd just use a straight str_replace).


Thanks

Guess i was just trying to over think it. Have not done much with files.


Steve



$out = basename($file, .html) . .com;

fairly limited i think, but simple.

--
Regards,
Anup Shukla

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Can't find .php3 files

2008-01-09 Thread Anup Shukla

Jim wrote:

Hi, Mike,

The include is more like
require ../admin/admin.php3 I don't know exactly how Apache performs 
its magic so I wasn't sure that the request for an include file would 
even pass through Apache's hands.  In my limited world, an include 
wouldn't have to involve Apache, just the file systems.




The admin.php3 seems to be 2 levels above the current dir.

What about

print realpath(../admin/admin.php3)

in the same script?

--
Regards,
Anup Shukla

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] is_executable() ???

2008-01-07 Thread Anup Shukla

Al wrote:

clearstatcache();
if(is_executable(PATH_TO_SOURCE_DIR . $filename)
{
code
}


is_executable() will only tell if the execute bit is set for the 
provided file.




Always returns true for:
foo.jpg
foo.php
foo.sh

And even if I feed it a non existing file.


Checking on a non-existing file basically is checking for the directory.
PATH_TO_SOURCE_DIR . $filename == PATH_TO_SOURCE_DIR if $filename == 

Directories generally have the permission 0755 which means they have the 
execute bit set, and hence the true result.




I found one ref that said is_executable() doesn't work in safemode, 
seems dumb if true.


If that's so, how can I test whether an uploaded file is executable?


Any file, under unix can be executable if the execute bit in the file 
permissions is set.


Make sure you umask settings are correct, so that files created do not 
have the execute bit set or use chmod on the file after uploading.


If you intend to find if the file is an executable in the Windows 
sense... is_executable() will not help you.


Try examining the mime type of the file.. (PECL::Fileinfo),
though it may of be of little help.

Additionally, using is_uploaded_file() and move_uploaded_file() 
functions is recommended while dealing with uploaded content.




I'm on a NIX with Apache, etc.




--
Regards,
Anup Shukla

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php