How to convert string to boolean php

This method was posted by @lauthiamkok in the comments. I’m posting it here as an answer to call more attention to it. Depending on your needs, you should consider using filter_var() with the FILTER_VALIDATE_BOOLEAN flag. filter_var( true, FILTER_VALIDATE_BOOLEAN); // true filter_var( ‘true’, FILTER_VALIDATE_BOOLEAN); // true filter_var( 1, FILTER_VALIDATE_BOOLEAN); // true filter_var( ‘1’, FILTER_VALIDATE_BOOLEAN); // true … Read more

How to convert an array to object in PHP?

In the simplest case, it’s probably sufficient to “cast” the array as an object: $object = (object) $array; Another option would be to instantiate a standard class as a variable, and loop through your array while re-assigning the values: $object = new stdClass(); foreach ($array as $key => $value) { $object->$key = $value; } As … Read more

Safely casting long to int in Java

A new method has been added with Java 8 to do just that. import static java.lang.Math.toIntExact; long foo = 10L; int bar = toIntExact(foo); Will throw an ArithmeticException in case of overflow. See: Math.toIntExact(long) Several other overflow safe methods have been added to Java 8. They end with exact. Examples: Math.incrementExact(long) Math.subtractExact(long, long) Math.decrementExact(long) Math.negateExact(long), … Read more

When to use reinterpret_cast?

The C++ standard guarantees the following: static_casting a pointer to and from void* preserves the address. That is, in the following, a, b and c all point to the same address: int* a = new int(); void* b = static_cast<void*>(a); int* c = static_cast<int*>(b); reinterpret_cast only guarantees that if you cast a pointer to a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)