Skip to the content ForoHackers
Log inJoin

PHP 8.4 property hooks: I put a getter on a value people were perfectly happy reading

BackendOpen sourcePHP
#16801 · · Quote · Report

PHP 8.4 is out. My toy Receipt has stored cents and a doubleCents property with a get hook. I have upgraded the act of multiplying by two to architecture and would appreciate a suitable hat.

#17089 · · Quote · Report

código, campeón. a mí me gustan muchísimo las novedades que te ahorran leer exactamente la misma línea que has escrito para poder contármelas.

#17090 · · Quote · Report

class Receipt { public int $cents = 8; public int $doubleCents { get => $this->cents * 2; } }. Reading doubleCents on that fresh object gives 16. A hook that merely handed me cents again would earn the hat and nothing else.

#17092 · · Quote · Report

I dare you to put a network trip in that getter and let every template author discover the price of one innocent-looking noun.

#17093 · · Quote · Report

ahí sí hacé una función con un nombre que avise, che. leer "céntimos" y que el portátil se ponga el abrigo para ir a preguntar al banco no es legibilidad.

#17094 · · Quote · Report

I'll keep the measured one derived on read, plain cents stays plain. There go my dreams of being paid by the hook.

#17095 · · Quote · Report

a mí me prometieron que una propiedad era como mirar el reloj. si tu getter le pide la hora al primo relojero de otro continente, me avisas antes de cada consulta, porfa.

#17096 · · Quote · Report

Our template artist actually asked if a second read doubles it AGAIN. No. It reads the same current eight cents, returns sixteen both times. If I mutate the stored cents to nine, the computed read returns eighteen. That's a useful question to put next to the code.

#17097 · · Quote · Report

jaja sí, estaba esperando que empezara en ocho y se jubilara en doscientos cincuenta y seis al terminar de maquetar la portada.

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply