[PHP] Import symbol table into function' scope.

2011-06-15 Thread Дмитрий Степанов
Hello, everybody.

Consider the following code:

class DB {
public function query( $sql) {
// ... some "magic" of DB querying
}
}

class DBReader {
public $DB;// instance of DB
public function __call( $methodName, $args) {
return call_user_func_array( array( $this, $methodName), $args);
}
protected function readSomething() {
$sql ='SELECT ...';
$result =$this->DB->query( $sql);
}
protected function readSomethingElse() {
// ... very similar to DBReader::readSomething()
}
//  + other methods like DBReader::readSomething()
}

If you take a look at DBReader::readSomething(), you'll see that I am
referencing database object and performing query via "$this->DB->query()".
If you do a lot of database queries, your code becomes bloated with
"$this->DB->..." and usually gets not so well readable (at least for me).

Since I have a lot of methods, that are similar to DBReader::readSomething()
(which perform DB queries), I would like to optimize readability of the DB
querying code. Right now I would do it in the following way:

// 1) reference database object inside the method
$DB =$this->DB;

// 2) do whatever I need with the DB
$DB->query( $sql);
$DB->numRows();
// ... or whatever

This way the code looks nicer and is, in fact, shorter.

So I wonder if there is any way to import scope (symbol table) into the
method DBReader::readSomething()? By importing the variables into the
function body,
I would like to avoid the "1) reference database object inside the method"
step so that $DB becomes instantly available:

protected function readSomething() {
$sql ='SELECT ...';
$result =$DB->query( $sql);// like this
}

AFAIK, there is no such call_user_func* function that would allow importing
of symbol table into the called fn.
What I would expect to be possible:

public function __call( $methodName, $args) {
$scope =array( 'DB' =>$this->DB);
return call_user_func_array( array( $this, $methodName), $args, $scope);//
note the $scope array, that is being passed here
}

The effect of such call to call_user_func_array() I would expect to be
equivalent with same as regular call to call_user_func_array(), but with
additional
call to extract( $scope, EXTR_REFS) right at the top of the function's body.

Does anybody have some ideas how I can get this working?

If there is no way to get this working with current PHP feature set, then I
would like to propose to extend call_user_func_array() to support $scope
argument.
What do you think about this?

P.S.: don't ask why I don't just simply make DBReader::readSomething() to be
public method. That's not the case.

P.S.: a very similar scope importing technique I am using with the PHP
template files I use in my web projects. As you know, include() is,
literally, "injecting" code
from the file into the current scope, thus making current symbol available
to the included code:

index.php:

$x =5;
$y =10;
include("chart.php");

chart.php:

echo $x .',' .$y;

After processing index.php, the output would be "5,10".

P.S.: closures are capable of importing scope via use() statement:

$x =5;
$y =10;

$closure =function() use( $x, $y) {
  echo $x .',' .$y;
};

$closure();// would give output "5,10"

so I suppose that technically importing scope is not a big deal from the PHP
internals perspective.

Dmitry.


Re: [PHP] Ftp upload

2011-06-15 Thread Pete Ford

On 15/06/11 01:24, Marc Guay wrote:

I bought a 1GB external hard drive for $1000.  Did I just choke on my lunch?


If that was about 20 years ago, then it would be fine!

--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

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



Re: [PHP] Convert a PDF to a PNG?

2011-06-15 Thread Richard Quadling
On 15 June 2011 00:00, Tamara Temple  wrote:
>
> On Jun 14, 2011, at 5:48 PM, Brian Dunning wrote:
>
>> The PDFs are text only (white text on transparent background). I made them
>> using the FPDF, which was tedious to set up but works great. I've since
>> learned that I need PNG images, not PDFs. I know that I could rebuild them
>> using GD, but it's a lot of strings of text wrapping and formatting and that
>> would be the long, long way around.
>>
>> I've put in a request to see about getting ImageMagick/Ghostscript
>> installed... see how that goes.
>
> Well there's one on me... I didn't even *know* you could covert a text PDF
> to a PNG image
>
> The more you know 

It is just a case of rasterizing the PDF to a "display" and encoding
it to an image (or raw).

Admittedly, all the PDFs I work with are essentially images as the
source is a fax server.

I use PDF2PNG as this provides the cleanest output mechanism I've
found. But I didn't try GS which, theoretically, should be perfect.

Once in a PNG file, I use commandline IMagick to add a "tag" to the
top and the bottom of the fax (the bottom tag is rotated 180 degrees).
The tag can then be read regardless of the orientation of the fax when
the user scanned it. Processing several thousand faxes a day. For 6
years or so. A LOT of paper saved at our end.




-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

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



Re: [PHP] Ftp upload

2011-06-15 Thread Marc Guay
> If that was about 20 years ago, then it would be fine!

Would have been around 1992, good guesswork!

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



Re: [PHP] Ftp upload

2011-06-15 Thread Steve Staples
On Wed, 2011-06-15 at 07:42 -0400, Marc Guay wrote:
> > If that was about 20 years ago, then it would be fine!
> 
> Would have been around 1992, good guesswork!
> 

ugh, i feel old now (even though i am not)... 20 years ago is 1991... i
got my car/motorcycle license in 1992 at the age of 16...

-- 

Steve Staples
Web Application Developer
519.258.2333 x8414


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



[PHP] PHP and Windows 7 g6-bit

2011-06-15 Thread Byron Como

Does the precompiled windows binary work on win 7 64?

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



Re: [PHP] Import symbol table into function' scope.

2011-06-15 Thread David Harkness
2011/6/15 Дмитрий Степанов 

> So I wonder if there is any way to import scope (symbol table) into the
> method DBReader::readSomething()?
>

Since you're using call_user_func_array() to call your internal methods
already (just to expose protected methods publicly?), you could add $DB as a
parameter.

public function __call($method, $args) {
array_unshift($args, $this->DB);
return call_user_func_array( array( $this, $method), $args);
}

protected function readSomething($DB) {
$DB->query(...);
$DB->numRows();
...
}

I would advise getting used to the $this-> everywhere. I can from Java where
that's not required but don't really mind it anymore. However, the above
would work and be automatic once you added the parameter to each method.

Peace,
David


[PHP] PHP and Windows 7 64-bit

2011-06-15 Thread Byron Como

Does the precompiled windows binary work on win 7 64?

I downloaded the apache installer, works with no problems.
I got the php5 VC6 x86 Thread Safe version. It says "x86" so I'm 
guessing that's the problem. I can't find a current 64-bit version.


Error message:

Faulting application name: httpd.exe, version: 2.2.19.0, time stamp: 
0x4dd6eda8

Faulting module name: php5ts.dll, version: 5.2.17.17, time stamp: 0x4d25fb49
Exception code: 0xc005
Fault offset: 0x000f424c
Faulting process id: 0xa7c
Faulting application start time: 0x01cc2b64b44cc59e
Faulting application path: C:\server\Apache2.2\bin\httpd.exe
Faulting module path: C:\server\PHP\php5ts.dll
Report Id: f2e941ea-9757-11e0-a2f1-005056c8

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



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



Re: [PHP] PHP and Windows 7 g6-bit

2011-06-15 Thread Tim Thorburn

On 6/15/2011 11:37 AM, Byron Como wrote:

Does the precompiled windows binary work on win 7 64?

It does, however if you're using Apache as your webserver, for PHP 5.3+ 
you won't be able to use the binaries from apache.org for Windows.  
There is a link to Apache Lounge found here: 
http://windows.php.net/download/ which instructs you to download a VC9 
compiled version of Apache.


If you're using IIS, I think you can just download the version of PHP 
you're after and go.


Re: [PHP] PHP and Windows 7 g6-bit (Solved)

2011-06-15 Thread Byron Como

On 6/15/2011 1:59 PM, Tim Thorburn wrote:

On 6/15/2011 11:37 AM, Byron Como wrote:

Does the precompiled windows binary work on win 7 64?

It does, however if you're using Apache as your webserver, for PHP 
5.3+ you won't be able to use the binaries from apache.org for 
Windows.  There is a link to Apache Lounge found here: 
http://windows.php.net/download/ which instructs you to download a VC9 
compiled version of Apache.


If you're using IIS, I think you can just download the version of PHP 
you're after and go.



The documentation on this page:

http://windows.php.net/download/

... is wrong/out of date and should be corrected. If I am mistaken I 
humbly apologize.


Sincerly,
Byron Como

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



[PHP] How to PHP get bit depth of a given PNG image file?

2011-06-15 Thread Nam Gi VU
 Hi everyone,

In PHP code, given an .png image path, I need to detect the bit-depth of
that image. How can I do that?

I've tried to use getImageSize() and read the bits as below sample code but
it always returns '8' for 24-bits/32-bits image.

Please help.

class Utils {
//Ham de lay bits cua image

public static function getBits($image) {

$info = getImageSize($image);
return $info['bits'];


}
}

Hope to hear from all of you!
Regards,
Nam.

p.s I also post this issue on stackoverflow.com which is
here
.


Re: [PHP] How to PHP get bit depth of a given PNG image file?

2011-06-15 Thread Mattias Thorslund

On 06/15/2011 10:11 PM, Nam Gi VU wrote:

  Hi everyone,

In PHP code, given an .png image path, I need to detect the bit-depth of
that image. How can I do that?

I've tried to use getImageSize() and read the bits as below sample code but
it always returns '8' for 24-bits/32-bits image.


Reading the manual, it says:

"
channels will be 3 for RGB pictures and 4 for CMYK pictures.
bits is the number of bits for each color.
"

So, to get the total bit depth, I think you need to multiply by the 
number of colors, which is in the "channels" element.


Cheers,

Mattias


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



Re: [PHP] How to PHP get bit depth of a given PNG image file?

2011-06-15 Thread Nam Gi VU
Thank you Mattias,

I'll look at `channels` again.

Regards,
Nam



On Thu, Jun 16, 2011 at 1:06 PM, Mattias Thorslund wrote:

> On 06/15/2011 10:11 PM, Nam Gi VU wrote:
>
>>  Hi everyone,
>>
>> In PHP code, given an .png image path, I need to detect the bit-depth of
>> that image. How can I do that?
>>
>> I've tried to use getImageSize() and read the bits as below sample code
>> but
>> it always returns '8' for 24-bits/32-bits image.
>>
>
> Reading the manual, it says:
>
> "
> channels will be 3 for RGB pictures and 4 for CMYK pictures.
> bits is the number of bits for each color.
> "
>
> So, to get the total bit depth, I think you need to multiply by the number
> of colors, which is in the "channels" element.
>
> Cheers,
>
> Mattias
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>